/* * This moves the scale field to the given location. */ static void _moveCDKFScale (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag) { CDKFSCALE *scale = (CDKFSCALE *)object; /* Declare local variables. */ int currentX = getbegx(scale->win); int currentY = getbegy(scale->win); int xpos = xplace; int ypos = yplace; int xdiff = 0; int ydiff = 0; /* * If this is a relative move, then we will adjust where we want * to move to. */ if (relative) { xpos = getbegx(scale->win) + xplace; ypos = getbegy(scale->win) + yplace; } /* Adjust the window if we need to. */ alignxy (WindowOf(scale), &xpos, &ypos, scale->boxWidth, scale->boxHeight); /* Get the difference. */ xdiff = currentX - xpos; ydiff = currentY - ypos; /* Move the window to the new location. */ moveCursesWindow(scale->win, -xdiff, -ydiff); if (scale->labelWin != 0) { moveCursesWindow(scale->labelWin, -xdiff, -ydiff); } moveCursesWindow(scale->fieldWin, -xdiff, -ydiff); /* If there is a shadow box we have to move it too. */ if (scale->shadowWin != 0) { moveCursesWindow(scale->shadowWin, -xdiff, -ydiff); } /* Touch the windows so they 'move'. */ touchwin (WindowOf(scale)); wrefresh (WindowOf(scale)); /* Redraw the window, if they asked for it. */ if (refresh_flag) { drawCDKFScale (scale, ObjOf(scale)->box); } }
/* * This moves the alphalist field to the given location. */ static void _moveCDKAlphalist (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag) { CDKALPHALIST *alphalist = (CDKALPHALIST *)object; /* Declare local variables. */ int currentX = getbegx(alphalist->win); int currentY = getbegy(alphalist->win); int xpos = xplace; int ypos = yplace; int xdiff = 0; int ydiff = 0; /* * If this is a relative move, then we will adjust where we want * to move to. */ if (relative) { xpos = getbegx(alphalist->win) + xplace; ypos = getbegy(alphalist->win) + yplace; } /* Adjust the window if we need to. */ alignxy (WindowOf(alphalist), &xpos, &ypos, alphalist->boxWidth, alphalist->boxHeight); /* Get the difference. */ xdiff = currentX - xpos; ydiff = currentY - ypos; /* Move the window to the new location. */ moveCursesWindow(alphalist->win, -xdiff, -ydiff); /* If there is a shadow box we have to move it too. */ if (alphalist->shadowWin != 0) { moveCursesWindow(alphalist->shadowWin, -xdiff, -ydiff); } /* Move the sub-widgets. */ moveCDKEntry (alphalist->entryField, xplace, yplace, relative, FALSE); moveCDKScroll (alphalist->scrollField, xplace, yplace, relative, FALSE); /* Touch the windows so they 'move'. */ touchwin (WindowOf(alphalist)); wrefresh (WindowOf(alphalist)); /* Redraw the window, if they asked for it. */ if (refresh_flag) { drawCDKAlphalist (alphalist, ObjOf(alphalist)->box); } }
static void bw_show_value (float val, bw_show_t *bw, int idx) { float w; int pos; float delta; float minval,maxval; WINDOW *bw_bar_w = panel_window (bw->bar_p[idx]); WINDOW *bw_cell_w = panel_window (bw->cell_p[idx]); PANEL *bw_slider_p = bw->slider_p[idx]; minval = 0.01; maxval = 5.00; delta = maxval - minval; w = getmaxx (bw_bar_w) - 1; pos = (w/delta) * val; if (val >= minval && val <=maxval) { move_panel (bw_slider_p,getbegy (panel_window (bw_slider_p)),getbegx (bw_bar_w) + pos ); } mvwprintw (bw_cell_w,0,0,"%f",val); update_panels (); doupdate (); return; }
static int init_object(BOX * data, WINDOW *parent, int x, int y, int width, int height, BOX_DRAW box_draw, int code) { data->parent = parent; data->x = x; data->y = y; data->width = width; data->height = height; data->box_draw = box_draw; data->window = derwin(data->parent, data->height, data->width, data->y, data->x); if (data->window == 0) return -1; (void) keypad(data->window, TRUE); dlg_mouse_setbase(getbegx(parent), getbegy(parent)); if (code == 'D') { dlg_mouse_mkbigregion(y + 1, x + MON_WIDE, height - 1, width - MON_WIDE, KEY_MAX, 1, MON_WIDE, 3); } else { dlg_mouse_mkregion(y, x, height, width, code); } return 0; }
void dlg_trace_win(WINDOW *win) { if (myFP != 0) { int y, x; int j, k; int rc = getmaxy(win); int cc = getmaxx(win); chtype ch, c2; fprintf(myFP, "window %dx%d at %d,%d\n", rc, cc, getbegy(win), getbegx(win)); getyx(win, y, x); for (j = 0; j < rc; ++j) { fprintf(myFP, "%3d:", j); for (k = 0; k < cc; ++k) { ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); c2 = dlg_asciibox(ch); if (c2 != 0) { ch = c2; } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) { ch = '.'; } fputc((int) (ch & 0xff), myFP); } fputc('\n', myFP); } wmove(win, y, x); fflush(myFP); } }
static int init_object(BOX * data, WINDOW *parent, int x, int y, int width, int height, int period, int value, int code) { data->parent = parent; data->x = x; data->y = y; data->width = width; data->height = height; data->period = period; data->value = value % period; data->window = derwin(data->parent, data->height, data->width, data->y, data->x); if (data->window == 0) return -1; (void) keypad(data->window, TRUE); mouse_setbase(getbegx(parent), getbegy(parent)); mouse_mkregion(y, x, height, width, code); return 0; }
/* * This moves the scroll field to the given location. */ static void _moveCDKScroll (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag) { /* *INDENT-EQLS* */ CDKSCROLL *scrollp = (CDKSCROLL *)object; int currentX = getbegx (scrollp->win); int currentY = getbegy (scrollp->win); int xpos = xplace; int ypos = yplace; int xdiff = 0; int ydiff = 0; /* * If this is a relative move, then we will adjust where we want * to move to. */ if (relative) { xpos = getbegx (scrollp->win) + xplace; ypos = getbegy (scrollp->win) + yplace; } /* Adjust the window if we need to. */ alignxy (WindowOf (scrollp), &xpos, &ypos, scrollp->boxWidth, scrollp->boxHeight); /* Get the difference. */ xdiff = currentX - xpos; ydiff = currentY - ypos; /* Move the window to the new location. */ moveCursesWindow (scrollp->win, -xdiff, -ydiff); moveCursesWindow (scrollp->listWin, -xdiff, -ydiff); moveCursesWindow (scrollp->shadowWin, -xdiff, -ydiff); moveCursesWindow (scrollp->scrollbarWin, -xdiff, -ydiff); /* Touch the windows so they 'move'. */ refreshCDKWindow (WindowOf (scrollp)); /* Redraw the window, if they asked for it. */ if (refresh_flag) { drawCDKScroll (scrollp, ObjOf (scrollp)->box); } }
/* * This moves the widget's data field to the given location. */ static void _moveCDKScale (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag) { CDKSCALE *widget = (CDKSCALE *) object; int currentX = getbegx (widget->win); int currentY = getbegy (widget->win); int xpos = xplace; int ypos = yplace; int xdiff = 0; int ydiff = 0; /* * If this is a relative move, then we will adjust where we want * to move to. */ if (relative) { xpos = getbegx (widget->win) + xplace; ypos = getbegy (widget->win) + yplace; } /* Adjust the window if we need to. */ alignxy (WindowOf (widget), &xpos, &ypos, widget->boxWidth, widget->boxHeight); /* Get the difference. */ xdiff = currentX - xpos; ydiff = currentY - ypos; /* Move the window to the new location. */ moveCursesWindow (widget->win, -xdiff, -ydiff); moveCursesWindow (widget->labelWin, -xdiff, -ydiff); moveCursesWindow (widget->fieldWin, -xdiff, -ydiff); moveCursesWindow (widget->shadowWin, -xdiff, -ydiff); /* Touch the windows so they 'move'. */ refreshCDKWindow (WindowOf (widget)); /* Redraw the window, if they asked for it. */ if (refresh_flag) { drawCDKScale (widget, ObjOf (widget)->box); } }
void dlg_draw_arrows2(WINDOW *win, int top_arrow, int bottom_arrow, int x, int top, int bottom, chtype attr, chtype borderattr) { chtype save = dlg_get_attrs(win); int cur_x, cur_y; int limit_x = getmaxx(win); bool draw_top = TRUE; bool is_toplevel = (wgetparent(win) == stdscr); getyx(win, cur_y, cur_x); /* * If we're drawing a centered title, do not overwrite with the arrows. */ if (dialog_vars.title && is_toplevel && (top - getbegy(win)) < MARGIN) { int have = (limit_x - dlg_count_columns(dialog_vars.title)) / 2; int need = x + 5; if (need > have) draw_top = FALSE; } if (draw_top) { (void) wmove(win, top, x); if (top_arrow) { (void) wattrset(win, merge_colors(uarrow_attr, attr)); (void) add_acs(win, ACS_UARROW); (void) waddstr(win, "(-)"); } else { (void) wattrset(win, attr); (void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT); } } mouse_mkbutton(top, x - 1, 6, KEY_PPAGE); (void) wmove(win, bottom, x); if (bottom_arrow) { (void) wattrset(win, merge_colors(darrow_attr, borderattr)); (void) add_acs(win, ACS_DARROW); (void) waddstr(win, "(+)"); } else { (void) wattrset(win, borderattr); (void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT); } mouse_mkbutton(bottom, x - 1, 6, KEY_NPAGE); (void) wmove(win, cur_y, cur_x); wrefresh(win); (void) wattrset(win, save); }
void string_input_popup::show_history( utf8_wrapper &ret ) { if( _identifier.empty() ) { return; } std::vector<std::string> &hist = uistate.gethistory( _identifier ); uimenu hmenu; hmenu.title = _( "d: delete history" ); hmenu.return_invalid = true; for( size_t h = 0; h < hist.size(); h++ ) { hmenu.addentry( h, true, -2, hist[h] ); } if( !ret.empty() && ( hmenu.entries.empty() || hmenu.entries[hist.size() - 1].txt != ret.str() ) ) { hmenu.addentry( hist.size(), true, -2, ret.str() ); hmenu.selected = hist.size(); } else { hmenu.selected = hist.size() - 1; } // number of lines that make up the menu window: title,2*border+entries hmenu.w_height = 3 + hmenu.entries.size(); hmenu.w_y = getbegy( w ) - hmenu.w_height; if( hmenu.w_y < 0 ) { hmenu.w_y = 0; hmenu.w_height = std::max( getbegy( w ), 4 ); } hmenu.w_x = getbegx( w ); hmenu.query(); if( hmenu.ret >= 0 && hmenu.entries[hmenu.ret].txt != ret.str() ) { ret = hmenu.entries[hmenu.ret].txt; if( hmenu.ret < ( int )hist.size() ) { hist.erase( hist.begin() + hmenu.ret ); hist.push_back( ret.str() ); } _position = ret.size(); } else if( hmenu.keypress == 'd' ) { hist.clear(); } }
static void init_list(LIST * list, WINDOW *par, WINDOW *win, int mousex) { list->par = par; list->win = win; list->length = 0; list->offset = 0; list->choice = 0; list->mousex = mousex; list->allocd = 0; list->data = 0; dlg_mouse_mkbigregion(getbegy(win), getbegx(win), getmaxy(win), getmaxx(win), mousex, 1, 1, 1 /* by lines */ ); }
bool input_context::get_coordinates(WINDOW* capture_win, int& x, int& y) { if (!coordinate_input_received) { return false; } int view_columns = getmaxx(capture_win); int view_rows = getmaxy(capture_win); int win_left = getbegx(capture_win) - VIEW_OFFSET_X; int win_right = win_left + view_columns - 1; int win_top = getbegy(capture_win) - VIEW_OFFSET_Y; int win_bottom = win_top + view_rows - 1; if (coordinate_x < win_left || coordinate_x > win_right || coordinate_y < win_top || coordinate_y > win_bottom) { return false; } x = g->ter_view_x - ((view_columns/2) - coordinate_x); y = g->ter_view_y - ((view_rows/2) - coordinate_y); return true; }
/* * FIXME: must adjust position so it's within the parent! */ static int adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen) { int result; int bottom = current_lines + SP->_topstolen - stolen; int myLines = win->_maxy + 1; int myCols = win->_maxx + 1; T((T_CALLED("adjust_window(%p,%d,%d) currently %dx%d at %d,%d"), win, ToLines, ToCols, getmaxy(win), getmaxx(win), getbegy(win), getbegx(win))); if (win->_begy >= bottom) { win->_begy += (ToLines - current_lines); } else { if (myLines == current_lines - stolen && ToLines != current_lines) myLines = ToLines - stolen; else if (myLines == current_lines && ToLines != current_lines) myLines = ToLines; } if (myLines > ToLines) myLines = ToLines; if (myCols > ToCols) myCols = ToCols; if (myLines == current_lines && ToLines != current_lines) myLines = ToLines; if (myCols == current_cols && ToCols != current_cols) myCols = ToCols; result = wresize(win, myLines, myCols); returnCode(result); }
static WINDOW * create_my_subwin(WINDOW *parent) { PAIR ul, lr; WINDOW *result = 0; if (getwindow(parent, &ul, &lr)) { result = subwin(parent, lines_of(ul, lr), cols_of(ul, lr), ul.y + getbegy(parent), ul.x + getbegx(parent)); if (result != 0) { fill_window(result, 's'); add_window(parent, result); } } if (result == 0) result = parent; return result; }
int set_traits(WINDOW* w, game* g, player *u, int &points, int max_trait_points) { draw_tabs(w, "TRAITS"); WINDOW* w_description = newwin(3, 78, 21 + getbegy(w), 1 + getbegx(w)); // Track how many good / bad POINTS we have; cap both at MAX_TRAIT_POINTS int num_good = 0, num_bad = 0; for (int i = 0; i < PF_SPLIT; i++) { if (u->has_trait(i)) num_good += traits[i].points; } for (int i = PF_SPLIT + 1; i < PF_MAX; i++) { if (u->has_trait(i)) num_bad += abs(traits[i].points); } for (int i = 0; i < 16; i++) {//preparation: draw disadvantages list mvwprintz(w, 5 + i, 40, c_dkgray, "\ "); if (u->has_trait(PF_SPLIT + 1 + i))//highlight disadvantages mvwprintz(w, 5 + i, 40, COL_TR_BAD_ON_PAS, _(traits[PF_SPLIT + 1 + i].name.c_str())); else mvwprintz(w, 5 + i, 40, COL_TR_BAD_OFF_PAS, _(traits[PF_SPLIT + 1 + i].name.c_str())); }
/* * This creates the alphalist widget. */ CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, char **list, int listSize, chtype fillerChar, chtype highlight, boolean Box, boolean shadow) { CDKALPHALIST *alphalist = 0; chtype *chtypeLabel = 0; int parentWidth = getmaxx (cdkscreen->window); int parentHeight = getmaxy (cdkscreen->window); int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int tempWidth = 0; int tempHeight = 0; int labelLen = 0; int x, junk2; static const struct { int from; int to; } bindings[] = { { CDK_BACKCHAR, KEY_PPAGE }, { CDK_FORCHAR, KEY_NPAGE }, }; if ((alphalist = newCDKObject (CDKALPHALIST, &my_funcs)) == 0 || !createList (alphalist, list, listSize)) { destroyCDKObject (alphalist); return (0); } setCDKAlphalistBox (alphalist, Box); /* * If the height is a negative value, the height will * be ROWS-height, otherwise, the height will be the * given height. */ boxHeight = setWidgetDimension (parentHeight, height, 0); /* * If the width is a negative value, the width will * be COLS-width, otherwise, the width will be the * given width. */ boxWidth = setWidgetDimension (parentWidth, width, 0); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { chtypeLabel = char2Chtype (label, &labelLen, &junk2); freeChtype (chtypeLabel); } /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the file selector window. */ alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos); if (alphalist->win == 0) { destroyCDKObject (alphalist); return (0); } keypad (alphalist->win, TRUE); /* Set some variables. */ ScreenOf (alphalist) = cdkscreen; alphalist->parent = cdkscreen->window; alphalist->highlight = highlight; alphalist->fillerChar = fillerChar; alphalist->boxHeight = boxHeight; alphalist->boxWidth = boxWidth; initExitType (alphalist); alphalist->shadow = shadow; alphalist->shadowWin = 0; /* Do we want a shadow? */ if (shadow) { alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Create the entry field. */ tempWidth = (isFullWidth (width) ? FULL : boxWidth - 2 - labelLen); alphalist->entryField = newCDKEntry (cdkscreen, getbegx (alphalist->win), getbegy (alphalist->win), title, label, A_NORMAL, fillerChar, vMIXED, tempWidth, 0, 512, Box, FALSE); if (alphalist->entryField == 0) { destroyCDKObject (alphalist); return (0); } setCDKEntryLLChar (alphalist->entryField, ACS_LTEE); setCDKEntryLRChar (alphalist->entryField, ACS_RTEE); /* Set the key bindings for the entry field. */ bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist); /* Set up the post-process function for the entry field. */ setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist); /* * Create the scrolling list. It overlaps the entry field by one line if * we are using box-borders. */ tempHeight = getmaxy (alphalist->entryField->win) - BorderOf (alphalist); tempWidth = (isFullWidth (width) ? FULL : boxWidth - 1); alphalist->scrollField = newCDKScroll (cdkscreen, getbegx (alphalist->win), getbegy (alphalist->entryField->win) + tempHeight, RIGHT, boxHeight - tempHeight, tempWidth, 0, list, listSize, NONUMBERS, A_REVERSE, Box, FALSE); setCDKScrollULChar (alphalist->scrollField, ACS_LTEE); setCDKScrollURChar (alphalist->scrollField, ACS_RTEE); /* Setup the key bindings. */ for (x = 0; x < (int) SIZEOF (bindings); ++x) bindCDKObject (vALPHALIST, alphalist, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to); registerCDKObject (cdkscreen, vALPHALIST, alphalist); return (alphalist); }
int set_traits(WINDOW* w, player *u, int &points) { draw_tabs(w, "TRAITS"); WINDOW* w_description = newwin(3, 78, 21 + getbegy(w), 1 + getbegx(w)); // Track how many good / bad POINTS we have; cap both at MAX_TRAIT_POINTS int num_good = 0, num_bad = 0; for (int i = 0; i < PF_SPLIT; i++) { if (u->has_trait(i)) num_good += traits[i].points; } for (int i = PF_SPLIT + 1; i < PF_MAX; i++) { if (u->has_trait(i)) num_bad += abs(traits[i].points); } for (int i = 0; i < 16; i++) { mvwprintz(w, 5 + i, 40, c_dkgray, "\ "); mvwprintz(w, 5 + i, 40, c_dkgray, traits[PF_SPLIT + 1 + i].name.c_str()); } mvwprintz(w,11,32, c_ltgray, "h l"); mvwprintz(w,12,32, c_ltgray, "< >"); mvwprintz(w,13,32, c_ltgray, "4 6"); mvwprintz(w,15,32, c_ltgray, "Space"); mvwprintz(w,16,31, c_ltgray,"Toggles"); int cur_adv = 1, cur_dis = PF_SPLIT + 1, cur_trait, traitmin, traitmax, xoff; nc_color col_on, col_off, hi_on, hi_off; bool using_adv = true; // True if we're selecting advantages, false if we're // selecting disadvantages do { mvwprintz(w, 3, 2, c_ltgray, "Points left: %d ", points); mvwprintz(w, 3,20, c_ltgreen, "%s%d/%d", (num_good < 10 ? " " : ""), num_good, MAX_TRAIT_POINTS); mvwprintz(w, 3,33, c_ltred, "%s%d/%d", (num_bad < 10 ? " " : ""), num_bad, MAX_TRAIT_POINTS); // Clear the bottom of the screen. mvwprintz(w_description, 0, 0, c_ltgray, " "); mvwprintz(w_description, 1, 0, c_ltgray, " "); mvwprintz(w_description, 2, 0, c_ltgray, " "); if (using_adv) { col_on = COL_TR_GOOD_ON; col_off = COL_TR_GOOD_OFF; hi_on = hilite(col_on); hi_off = hilite(col_off); xoff = 2; cur_trait = cur_adv; traitmin = 1; traitmax = PF_SPLIT; mvwprintz(w, 3, 40, c_ltgray, " "); mvwprintz(w, 3, 40, COL_TR_GOOD, "%s costs %d points", traits[cur_adv].name.c_str(), traits[cur_adv].points); mvwprintz(w_description, 0, 0, COL_TR_GOOD, "%s", traits[cur_adv].description.c_str()); } else { col_on = COL_TR_BAD_ON; col_off = COL_TR_BAD_OFF; hi_on = hilite(col_on); hi_off = hilite(col_off); xoff = 40; cur_trait = cur_dis; traitmin = PF_SPLIT + 1; traitmax = PF_MAX; mvwprintz(w, 3, 40, c_ltgray, " "); mvwprintz(w, 3, 40, COL_TR_BAD, "%s earns %d points", traits[cur_dis].name.c_str(), traits[cur_dis].points * -1); mvwprintz(w_description, 0, 0, COL_TR_BAD, "%s", traits[cur_dis].description.c_str()); } if (cur_trait <= traitmin + 7) { for (int i = traitmin; i < traitmin + 16; i++) { mvwprintz(w, 5 + i - traitmin, xoff, c_ltgray, "\ "); // Clear the line if (i == cur_trait) { if (u->has_trait(i)) mvwprintz(w, 5 + i - traitmin, xoff, hi_on, traits[i].name.c_str()); else mvwprintz(w, 5 + i - traitmin, xoff, hi_off, traits[i].name.c_str()); } else { if (u->has_trait(i)) mvwprintz(w, 5 + i - traitmin, xoff, col_on, traits[i].name.c_str()); else mvwprintz(w, 5 + i - traitmin, xoff, col_off, traits[i].name.c_str()); } } } else if (cur_trait >= traitmax - 9) { for (int i = traitmax - 16; i < traitmax; i++) { mvwprintz(w, 21 + i - traitmax, xoff, c_ltgray, "\ "); // Clear the line if (i == cur_trait) { if (u->has_trait(i)) mvwprintz(w, 21 + i - traitmax, xoff, hi_on, traits[i].name.c_str()); else mvwprintz(w, 21 + i - traitmax, xoff, hi_off, traits[i].name.c_str()); } else { if (u->has_trait(i)) mvwprintz(w, 21 + i - traitmax, xoff, col_on, traits[i].name.c_str()); else mvwprintz(w, 21 + i - traitmax, xoff, col_off, traits[i].name.c_str()); } } } else {
/* * This allows the user to use the cursor keys to adjust the * position of the widget. */ void positionCDKButton (CDKBUTTON *button) { /* Declare some variables. */ int origX = getbegx (button->win); int origY = getbegy (button->win); chtype key = (chtype)0; boolean functionKey; /* Let them move the widget around until they hit return. */ while (key != KEY_ENTER) { key = (chtype)getchCDKObject (ObjOf (button), &functionKey); if (key == KEY_UP || key == '8') { if (getbegy (button->win) > 0) { moveCDKButton (button, 0, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_DOWN || key == '2') { if (getbegy (button->win) + getmaxy (button->win) < getmaxy (WindowOf (button)) - 1) { moveCDKButton (button, 0, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_LEFT || key == '4') { if (getbegx (button->win) > 0) { moveCDKButton (button, -1, 0, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_RIGHT || key == '6') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1) { moveCDKButton (button, 1, 0, TRUE, TRUE); } else { BEEP (); } } else if (key == '7') { if (getbegy (button->win) > 0 && getbegx (button->win) > 0) { moveCDKButton (button, -1, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == '9') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1 && getbegy (button->win) > 0) { moveCDKButton (button, 1, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == '1') { if (getbegx (button->win) > 0 && getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1) { moveCDKButton (button, -1, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == '3') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1 && getbegy (button->win) + getmaxy (button->win) < getmaxy (WindowOf (button)) - 1) { moveCDKButton (button, 1, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == '5') { moveCDKButton (button, CENTER, CENTER, FALSE, TRUE); } else if (key == 't') { moveCDKButton (button, getbegx (button->win), TOP, FALSE, TRUE); } else if (key == 'b') { moveCDKButton (button, getbegx (button->win), BOTTOM, FALSE, TRUE); } else if (key == 'l') { moveCDKButton (button, LEFT, getbegy (button->win), FALSE, TRUE); } else if (key == 'r') { moveCDKButton (button, RIGHT, getbegy (button->win), FALSE, TRUE); } else if (key == 'c') { moveCDKButton (button, CENTER, getbegy (button->win), FALSE, TRUE); } else if (key == 'C') { moveCDKButton (button, getbegx (button->win), CENTER, FALSE, TRUE); } else if (key == CDK_REFRESH) { eraseCDKScreen (ScreenOf (button)); refreshCDKScreen (ScreenOf (button)); } else if (key == KEY_ESC) { moveCDKButton (button, origX, origY, FALSE, TRUE); } else if (key != KEY_ENTER) { BEEP (); } } }
/* * This creates a file selection widget. */ CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, chtype fieldAttribute, chtype fillerChar, chtype highlight, char *dAttribute, char *fAttribute, char *lAttribute, char *sAttribute, boolean Box, boolean shadow) { /* Set up some variables. */ CDKFSELECT *fselect = newCDKObject(CDKFSELECT, &my_funcs); int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int entryWidth, x, labelLen, junk; chtype *chtypeString; /* * If the height is a negative value, the height will * be ROWS-height, otherwise, the height will be the * given height. */ boxHeight = setWidgetDimension (parentHeight, height, 0); /* * If the width is a negative value, the width will * be COLS-width, otherwise, the width will be the * given width. */ boxWidth = setWidgetDimension (parentWidth, width, 0); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make sure the box isn't too small. */ boxWidth = (boxWidth < 15 ? 15 : boxWidth); boxHeight = (boxHeight < 6 ? 6 : boxHeight); /* Make the file selector window. */ fselect->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the window null? */ if (fselect->win == 0) { return (0); } keypad (fselect->win, TRUE); /* Set some variables. */ ScreenOf(fselect) = cdkscreen; fselect->parent = cdkscreen->window; fselect->dirAttribute = copyChar (dAttribute); fselect->fileAttribute = copyChar (fAttribute); fselect->linkAttribute = copyChar (lAttribute); fselect->sockAttribute = copyChar (sAttribute); fselect->highlight = highlight; fselect->fillerCharacter = fillerChar; fselect->fieldAttribute = fieldAttribute; fselect->boxHeight = boxHeight; fselect->boxWidth = boxWidth; fselect->fileCounter = 0; fselect->pwd = 0; fselect->exitType = vNEVER_ACTIVATED; ObjOf(fselect)->box = Box; fselect->shadow = shadow; fselect->shadowWin = 0; /* Zero out the contents of the directory listing. */ for (x=0; x < MAX_ITEMS; x++) { fselect->dirContents[x] = 0; } /* Get the present working directory. */ setPWD(fselect); /* Get the contents of the current directory. */ setCDKFselectDirContents (fselect); /* Create the entry field in the selector. */ chtypeString = char2Chtype (label, &labelLen, &junk); freeChtype (chtypeString); entryWidth = boxWidth - labelLen - 3; fselect->entryField = newCDKEntry (cdkscreen, getbegx(fselect->win), getbegy(fselect->win), title, label, fieldAttribute, fillerChar, vMIXED, entryWidth, 0, 512, Box, FALSE); /* Make sure the widget was created. */ if (fselect->entryField == 0) { /* Clean up. */ freeCharList (fselect->dirContents, MAX_ITEMS); freeChar (fselect->pwd); freeChar (fselect->dirAttribute); freeChar (fselect->fileAttribute); freeChar (fselect->linkAttribute); freeChar (fselect->sockAttribute); deleteCursesWindow (fselect->win); return (0); } /* Set the lower left/right characters of the entry field. */ setCDKEntryLLChar (fselect->entryField, ACS_LTEE); setCDKEntryLRChar (fselect->entryField, ACS_RTEE); /* Define the callbacks for the entry field. */ bindCDKObject (vENTRY, fselect->entryField, KEY_UP, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_PPAGE, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('B'), fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_DOWN, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_NPAGE, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('F'), fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_TAB, completeFilenameCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('^'), displayFileInfoCB, fselect); /* Put the current working directory in the entry field. */ setCDKEntryValue (fselect->entryField, fselect->pwd); /* Create the scrolling list in the selector. */ fselect->scrollField = newCDKScroll (cdkscreen, getbegx(fselect->win), getbegy(fselect->win) + (fselect->entryField)->titleLines + 2, RIGHT, boxHeight - (fselect->entryField)->titleLines - 3, boxWidth-2, 0, fselect->dirContents, fselect->fileCounter, NONUMBERS, fselect->highlight, Box, FALSE); /* Set the lower left/right characters of the entry field. */ setCDKScrollULChar (fselect->scrollField, ACS_LTEE); setCDKScrollURChar (fselect->scrollField, ACS_RTEE); /* Do we want a shadow? */ if (shadow) { fselect->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Register this baby. */ registerCDKObject (cdkscreen, vFSELECT, fselect); /* Return the file selector pointer. */ return (fselect); }
int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkScreen = 0; CDKENTRY *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; chtype *holder = 0; chtype fieldAttr = A_NORMAL; char *answer = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; char filler = '.'; EDisplayType dType = vMIXED; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *buttons; char *filename; char *outputFile; char *initValue; char *title; char *label; char *tempFiller; int maxValue; int fieldWidth; int minValue; int xpos; int ypos; CDKparseParams(argc, argv, ¶ms, "d:f:i:m:B:F:L:M:O:T:" "X:Y:NS"); xpos = CDKparamValue(¶ms, 'X', CENTER); ypos = CDKparamValue(¶ms, 'Y', CENTER); boxWidget = CDKparamValue(¶ms, 'N', TRUE); shadowWidget = CDKparamValue(¶ms, 'S', FALSE); minValue = CDKparamValue(¶ms, 'm', 0); fieldWidth = CDKparamValue(¶ms, 'f', 0); maxValue = CDKparamValue(¶ms, 'M', 256); filename = CDKparamString(¶ms, 'f'); initValue = CDKparamString(¶ms, 'i'); buttons = CDKparamString(¶ms, 'B'); tempFiller = CDKparamString(¶ms, 'F'); label = CDKparamString(¶ms, 'L'); outputFile = CDKparamString(¶ms, 'O'); title = CDKparamString(¶ms, 'T'); if ((temp = CDKparamString(¶ms, 'd')) != 0) dType = char2DisplayType (temp); /* Make sure all the command line parameters were provided. */ if (fieldWidth <= 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Set up CDK. */ cursesWindow = initscr(); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor(); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* If the set the filler character, set it now. */ if (tempFiller != 0) { holder = char2Chtype (tempFiller, &j1, &j2); fieldAttr = A_ATTRIBUTES & holder[0]; filler = (chtype)holder[0]; freeChtype (holder); } /* Create the entry widget. */ widget = newCDKEntry (cdkScreen, xpos, ypos, title, label, fieldAttr, filler | fieldAttr, dType, fieldWidth, minValue, maxValue, boxWidget, FALSE); /* Check to make sure we created the dialog box. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK(); fprintf (stderr, "Error: Could not create the entry field. Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { buttonList = CDKsplitString (buttons, '\n'); buttonCount = CDKcountStrings (buttonList); buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), getbegy (widget->win) + widget->boxHeight - 1, 1, widget->boxWidth - 1, 0, 1, buttonCount, buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); CDKfreeStrings (buttonList); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the entry field. */ setCDKEntryLLChar (widget, ACS_LTEE); setCDKEntryLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the entry field to send a * Tab key to the button box widget. */ bindCDKObject (vENTRY, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vENTRY, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vENTRY, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKEntry (widget, ObjOf(widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKEntryBackgroundColor (widget, CDK_WIDGET_COLOR); /* If there was an initial value, set it. */ if (initValue != 0) { setCDKEntryValue (widget, initValue); } /* Activate the widget. */ answer = copyChar (activateCDKEntry (widget, 0)); /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKEntry (widget); destroyCDKScreen (cdkScreen); endCDK(); /* Print the value from the widget. */ if (answer != 0) { fprintf (fp, "%s\n", answer); freeChar (answer); } fclose (fp); /* Exit with the button number picked. */ ExitProgram (selection); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKMATRIX *widget = 0; CDKBUTTONBOX *buttonWidget = 0; chtype *holder = 0; char *buttons = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype filler = A_NORMAL | '.'; int rows = -1; int cols = -1; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **rowTitles; char **colTitles; char **rowTemp = 0; char **colTemp = 0; char **kolTemp = 0; char **buttonList = 0; int *colWidths; int *colTypes; int count, infoLines, x, y, j1, j2; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *defaultValue; char *myColTitles; char *myColTypes; char *myColWidths; char *myFiller; char *myRowTitles; char *outputFile; char *title; int vrows; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "c:d:r:t:w:v:B:F:O:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); vrows = CDKparamValue (¶ms, 'v', -1); myColTitles = CDKparamString (¶ms, 'c'); defaultValue = CDKparamString (¶ms, 'd'); myRowTitles = CDKparamString (¶ms, 'r'); myColTypes = CDKparamString (¶ms, 't'); myColWidths = CDKparamString (¶ms, 'w'); buttons = CDKparamString (¶ms, 'B'); myFiller = CDKparamString (¶ms, 'F'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Make sure all the needed command line parameters were provided. */ if ((myRowTitles == 0) || (myColTitles == 0) || (myColWidths == 0) || (vrows == -1)) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Convert the char * titles to a char **, offset by one */ rowTemp = CDKsplitString (myRowTitles, '\n'); rows = (int)CDKcountStrings ((CDK_CSTRING2)rowTemp); rowTitles = (char **)calloc ((size_t) rows + 1, sizeof (char *)); for (x = 0; x < rows; x++) { rowTitles[x + 1] = rowTemp[x]; } colTemp = CDKsplitString (myColTitles, '\n'); cols = (int)CDKcountStrings ((CDK_CSTRING2)colTemp); colTitles = (char **)calloc ((size_t) cols + 1, sizeof (char *)); for (x = 0; x < cols; x++) { colTitles[x + 1] = colTemp[x]; } /* Convert the column widths. */ kolTemp = CDKsplitString (myColWidths, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)kolTemp); colWidths = (int *)calloc ((size_t) count + 1, sizeof (int)); for (x = 0; x < count; x++) { colWidths[x + 1] = atoi (kolTemp[x]); } /* If they passed in the column types, convert them. */ if (myColTypes != 0) { char **ss = CDKsplitString (myColTypes, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)ss); colTypes = (int *)calloc ((size_t) MAXIMUM (cols, count) + 1, sizeof (int)); for (x = 0; x < count; x++) { colTypes[x + 1] = char2DisplayType (ss[x]); } CDKfreeStrings (ss); } else { /* If they didn't set default values. */ colTypes = (int *)calloc ((size_t) cols + 1, sizeof (int)); for (x = 0; x < cols; x++) { colTypes[x + 1] = vMIXED; } } cdkScreen = initCDKScreen (NULL); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* If the set the filler character, set it now. */ if (myFiller != 0) { holder = char2Chtype (myFiller, &j1, &j2); filler = holder[0]; freeChtype (holder); } /* Create the matrix widget. */ widget = newCDKMatrix (cdkScreen, xpos, ypos, rows, cols, vrows, cols, title, (CDK_CSTRING2)rowTitles, (CDK_CSTRING2)colTitles, colWidths, colTypes, 1, 1, filler, COL, boxWidget, TRUE, shadowWidget); free (rowTitles); free (colTitles); /* Make sure we could create the widget. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Cannot create the matrix. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* * If the user sent in a file of default values, read it and * stick the values read in from the file into the matrix. */ if (defaultValue != 0) { size_t limit = (size_t) ((rows + 1) * (cols + 1)); char **info = (char **)calloc (limit, sizeof (char *)); char **lineTemp = 0; /* Read the file. */ infoLines = CDKreadFile (defaultValue, &lineTemp); if (infoLines > 0) { int *subSize = (int *)calloc ((size_t) infoLines + 1, sizeof (int)); /* For each line, split on a CTRL-V. */ for (x = 0; x < infoLines; x++) { char **ss = CDKsplitString (lineTemp[x], CTRL ('V')); subSize[x + 1] = (int)CDKcountStrings ((CDK_CSTRING2)ss); for (y = 0; y < subSize[x + 1]; y++) { MY_INFO (x, y) = ss[y]; } free (ss); } CDKfreeStrings (lineTemp); setCDKMatrixCells (widget, (CDK_CSTRING2)info, rows, cols, subSize); for (x = 0; x < infoLines; x++) { for (y = 0; y < subSize[x + 1]; y++) { freeChar (MY_INFO (x, y)); } } free (info); free (subSize); } } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, NULL, 1, buttonCount, (CDK_CSTRING2)buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKMatrixLLChar (widget, ACS_LTEE); setCDKMatrixLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vMATRIX, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vMATRIX, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vMATRIX, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == (CDKBUTTONBOX *)NULL ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKMatrix (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKMatrixBackgroundColor (widget, CDK_WIDGET_COLOR); /* Let them play. */ activateCDKMatrix (widget, 0); /* Print out the matrix cells. */ if (widget->exitType == vNORMAL) { for (x = 0; x < widget->rows; x++) { for (y = 0; y < widget->cols; y++) { char *data = getCDKMatrixCell (widget, x, y); if (data != 0) { fprintf (fp, "%s%c", data, CTRL ('V')); } else { fprintf (fp, "%c", CTRL ('V')); } } fprintf (fp, "\n"); } } /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* cleanup (not really needed) */ CDKfreeStrings (buttonList); free (colTypes); free (colWidths); CDKfreeStrings (rowTemp); CDKfreeStrings (colTemp); CDKfreeStrings (kolTemp); destroyCDKMatrix (widget); destroyCDKScreen (cdkScreen); endCDK (); /* do this late, in case it was stderr */ fclose (fp); ExitProgram (selection); }
std::vector<point> game::target(int &x, int &y, int lowx, int lowy, int hix, int hiy, std::vector <monster> t, int &target, item *relevent) { std::vector<point> ret; int tarx, tary, junk, tart; int range=(hix-u.posx); // First, decide on a target among the monsters, if there are any in range if (t.size() > 0) { // Check for previous target if (target == -1) { // If no previous target, target the closest there is double closest = -1; double dist; for (int i = 0; i < t.size(); i++) { dist = rl_dist(t[i].posx, t[i].posy, u.posx, u.posy); if (closest < 0 || dist < closest) { closest = dist; target = i; } } } x = t[target].posx; y = t[target].posy; } else target = -1; // No monsters in range, don't use target, reset to -1 int sideStyle = (OPTIONS["SIDEBAR_STYLE"] == "Narrow"); int height = 13; int width = getmaxx(w_messages); int top = sideStyle ? getbegy(w_messages) : (getbegy(w_minimap) + getmaxy(w_minimap)); int left = getbegx(w_messages); WINDOW* w_target = newwin(height, width, top, left); wborder(w_target, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwprintz(w_target, 0, 2, c_white, "< "); if (!relevent) { // currently targetting vehicle to refill with fuel wprintz(w_target, c_red, _("Select a vehicle")); } else { if (relevent == &u.weapon && relevent->is_gun()) { wprintz(w_target, c_red, _("Firing %s (%d)"), // - %s (%d)", u.weapon.tname().c_str(),// u.weapon.curammo->name.c_str(), u.weapon.charges); } else { wprintz(w_target, c_red, _("Throwing %s"), relevent->tname().c_str()); } } wprintz(w_target, c_white, " >"); /* Annoying clutter @ 2 3 4. */ mvwprintz(w_target, getmaxy(w_target) - 4, 1, c_white, _("Move cursor to target with directional keys")); if (relevent) { mvwprintz(w_target, getmaxy(w_target) - 3, 1, c_white, _("'<' '>' Cycle targets; 'f' or '.' to fire")); mvwprintz(w_target, getmaxy(w_target) - 2, 1, c_white, _("'0' target self; '*' toggle snap-to-target")); } wrefresh(w_target); char ch; bool snap_to_target = OPTIONS["SNAP_TO_TARGET"]; do { if (m.sees(u.posx, u.posy, x, y, -1, tart)) ret = line_to(u.posx, u.posy, x, y, tart); else ret = line_to(u.posx, u.posy, x, y, 0); if(trigdist && trig_dist(u.posx,u.posy, x,y) > range) { bool cont=true; int cx=x; int cy=y; for (int i = 0; i < ret.size() && cont; i++) { if(trig_dist(u.posx,u.posy, ret[i].x, ret[i].y) > range) { ret.resize(i); cont=false; } else { cx=0+ret[i].x; cy=0+ret[i].y; } } x=cx;y=cy; } point center; if (snap_to_target) center = point(x, y); else center = point(u.posx + u.view_offset_x, u.posy + u.view_offset_y); // Clear the target window. for (int i = 1; i < getmaxy(w_target) - 5; i++) { for (int j = 1; j < getmaxx(w_target) - 2; j++) mvwputch(w_target, i, j, c_white, ' '); } m.build_map_cache(this); m.draw(this, w_terrain, center); // Draw the Monsters for (int i = 0; i < z.size(); i++) { if (u_see(&(z[i]))) { z[i].draw(w_terrain, center.x, center.y, false); } } // Draw the NPCs for (int i = 0; i < active_npc.size(); i++) { if (u_see(active_npc[i]->posx, active_npc[i]->posy)) active_npc[i]->draw(w_terrain, center.x, center.y, false); } if (x != u.posx || y != u.posy) { // Draw the player int atx = VIEWX + u.posx - center.x, aty = VIEWY + u.posy - center.y; if (atx >= 0 && atx < TERRAIN_WINDOW_WIDTH && aty >= 0 && aty < TERRAIN_WINDOW_HEIGHT) mvwputch(w_terrain, aty, atx, u.color(), '@'); // Only draw a highlighted trajectory if we can see the endpoint. // Provides feedback to the player, and avoids leaking information about tiles they can't see. if (u_see( x, y)) { for (int i = 0; i < ret.size(); i++) { int mondex = mon_at(ret[i].x, ret[i].y), npcdex = npc_at(ret[i].x, ret[i].y); // NPCs and monsters get drawn with inverted colors if (mondex != -1 && u_see(&(z[mondex]))) z[mondex].draw(w_terrain, center.x, center.y, true); else if (npcdex != -1) active_npc[npcdex]->draw(w_terrain, center.x, center.y, true); else m.drawsq(w_terrain, u, ret[i].x, ret[i].y, true,true,center.x, center.y); } } if (!relevent) { // currently targetting vehicle to refill with fuel vehicle *veh = m.veh_at(x, y); if (veh) mvwprintw(w_target, 1, 1, _("There is a %s"), veh->name.c_str()); } else mvwprintw(w_target, 1, 1, _("Range: %d"), rl_dist(u.posx, u.posy, x, y)); if (mon_at(x, y) == -1) { if (snap_to_target) mvwputch(w_terrain, VIEWY, VIEWX, c_red, '*'); else mvwputch(w_terrain, VIEWY + y - center.y, VIEWX + x - center.x, c_red, '*'); } else if (u_see(&(z[mon_at(x, y)]))) { z[mon_at(x, y)].print_info(this, w_target,2); } } wrefresh(w_target); wrefresh(w_terrain); wrefresh(w_status); refresh(); ch = input(); get_direction(this, tarx, tary, ch); if (tarx != -2 && tary != -2 && ch != '.') { // Direction character pressed int mondex = mon_at(x, y), npcdex = npc_at(x, y); if (mondex != -1 && u_see(&(z[mondex]))) z[mondex].draw(w_terrain, center.x, center.y, false); else if (npcdex != -1) active_npc[npcdex]->draw(w_terrain, center.x, center.y, false); else if (m.sees(u.posx, u.posy, x, y, -1, junk)) m.drawsq(w_terrain, u, x, y, false, true, center.x, center.y); else mvwputch(w_terrain, VIEWY, VIEWX, c_black, 'X'); x += tarx; y += tary; if (x < lowx) x = lowx; else if (x > hix) x = hix; if (y < lowy) y = lowy; else if (y > hiy) y = hiy; } else if ((ch == '<') && (target != -1)) { target--; if (target == -1) target = t.size() - 1; x = t[target].posx; y = t[target].posy; } else if ((ch == '>') && (target != -1)) { target++; if (target == t.size()) target = 0; x = t[target].posx; y = t[target].posy; } else if (ch == '.' || ch == 'f' || ch == 'F' || ch == '\n') { for (int i = 0; i < t.size(); i++) { if (t[i].posx == x && t[i].posy == y) target = i; } if (u.posx == x && u.posy == y) ret.clear(); break; } else if (ch == '0') { x = u.posx; y = u.posy; ret.clear(); } else if (ch == '*') snap_to_target = !snap_to_target; else if (ch == KEY_ESCAPE || ch == 'q') { // return empty vector (cancel) ret.clear(); break; } } while (true); return ret; }
int run_program(int flags, const char *cmd, ...) { va_list ap; struct winsize win; int ret; WINDOW *actionwin = NULL; char *scmd; char **args; const char *errstr = NULL; va_start(ap, cmd); vasprintf(&scmd, cmd, ap); va_end(ap); if (scmd == NULL) err(1, "vasprintf(&scmd, \"%s\", ...)", cmd); args = make_argv(scmd); /* Make curses save tty settings */ def_prog_mode(); (void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win); /* Apparently, we sometimes get 0x0 back, and that's not useful */ if (win.ws_row == 0) win.ws_row = 24; if (win.ws_col == 0) win.ws_col = 80; if ((flags & RUN_DISPLAY) != 0) { if (flags & RUN_FULLSCREEN) { wclear(stdscr); clearok(stdscr, 1); touchwin(stdscr); refresh(); actionwin = stdscr; } else actionwin = show_cmd(scmd, &win); } else win.ws_row -= 4; ret = launch_subwin(&actionwin, args, &win, flags, scmd, &errstr); fpurge(stdin); /* If the command failed, show command name */ if (actionwin == NULL && ret != 0 && !(flags & RUN_ERROR_OK)) actionwin = show_cmd(scmd, &win); if (actionwin != NULL) { int y, x; getyx(actionwin, y, x); if (actionwin != stdscr) mvaddstr(0, 4, msg_string(MSG_Status)); if (ret != 0) { if (actionwin == stdscr && x != 0) addstr("\n"); x = 1; /* force newline below */ standout(); addstr(errstr); standend(); } else { if (actionwin != stdscr) { standout(); addstr(msg_string(MSG_Finished)); standend(); } } clrtoeol(); refresh(); if ((ret != 0 && !(flags & RUN_ERROR_OK)) || (y + x != 0 && !(flags & RUN_PROGRESS))) { if (actionwin != stdscr) move(getbegy(actionwin) - 2, 5); else if (x != 0) addstr("\n"); addstr(msg_string(MSG_Hit_enter_to_continue)); refresh(); getchar(); } else { if (y + x != 0) { /* give user 1 second to see messages */ refresh(); sleep(1); } } } /* restore tty setting we saved earlier */ reset_prog_mode(); /* clean things up */ if (actionwin != NULL) { if (actionwin != stdscr) delwin(actionwin); if (errstr == 0 || !(flags & RUN_NO_CLEAR)) { wclear(stdscr); touchwin(stdscr); clearok(stdscr, 1); refresh(); } } free(scmd); free_argv(args); if (ret != 0 && flags & RUN_FATAL) exit(ret); return ret; }
bool player::install_bionics(game *g, it_bionic* type) { if (type == NULL) { debugmsg("Tried to install NULL bionic"); return false; } std::string bio_name = type->name.substr(5); // Strip off "CBM: " WINDOW* w = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0, (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); WINDOW* w_description = newwin(3, FULL_SCREEN_WIDTH-2, 21 + getbegy(w), 1 + getbegx(w)); werase(w); wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); int pl_skill = int_cur + skillLevel("electronics") * 4 + skillLevel("firstaid") * 3 + skillLevel("mechanics") * 2; int skint = int(pl_skill / 4); int skdec = int((pl_skill * 10) / 4) % 10; // Header text mvwprintz(w, 1, 1, c_white, "Installing bionics:"); mvwprintz(w, 1, 21, type->color, bio_name.c_str()); // Dividing bars for (int i = 1; i < 79; i++) { mvwputch(w, 2, i, c_ltgray, LINE_OXOX); mvwputch(w, 20, i, c_ltgray, LINE_OXOX); } mvwputch(w, 2, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w, 2, 79, c_ltgray, LINE_XOXX); // -| mvwputch(w, 20, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w, 20, 79, c_ltgray, LINE_XOXX); // -| // Init the list of bionics for (int i = 1; i < type->options.size(); i++) { bionic_id bio_id = type->options[i]; mvwprintz(w, i + 3, 1, (has_bionic(bio_id) ? c_ltred : c_ltblue), bionics[bio_id]->name.c_str()); } // Helper text mvwprintz(w, 3, 39, c_white, "Difficulty of this module: %d", type->difficulty); mvwprintz(w, 4, 39, c_white, "Your installation skill: %d.%d", skint, skdec); mvwprintz(w, 5, 39, c_white, "Installation requires high intelligence,"); mvwprintz(w, 6, 39, c_white, "and skill in electronics, first aid, and"); mvwprintz(w, 7, 39, c_white, "mechanics (in that order of importance)."); int chance_of_success = int((100 * pl_skill) / (pl_skill + 4 * type->difficulty)); mvwprintz(w, 9, 39, c_white, "Chance of success:"); nc_color col_suc; if (chance_of_success >= 95) col_suc = c_green; else if (chance_of_success >= 80) col_suc = c_ltgreen; else if (chance_of_success >= 60) col_suc = c_yellow; else if (chance_of_success >= 35) col_suc = c_ltred; else col_suc = c_red; mvwprintz(w, 9, 59, col_suc, "%d%%%%", chance_of_success); mvwprintz(w, 11, 39, c_white, "Failure may result in crippling damage,"); mvwprintz(w, 12, 39, c_white, "loss of existing bionics, genetic damage"); mvwprintz(w, 13, 39, c_white, "or faulty installation."); wrefresh(w); if (type->id == "bio_power_storage" || type->id == "bio_power_storage_mkII") { // No selection list; just confirm int pow_up = BATTERY_AMOUNT; if (type->id == "bio_power_storage_mkII") { pow_up = 10; } mvwprintz(w, 3, 1, h_ltblue, "Power Storage +%d", pow_up); mvwprintz(w_description, 0, 0, c_ltblue, "\ Installing this bionic will increase your total power storage by %d.\n\ Power is necessary for most bionics to function. You also require a\n\ charge mechanism, which must be installed from another CBM.", pow_up); InputEvent input; wrefresh(w_description); wrefresh(w); do input = get_input(); while (input != Confirm && input != Cancel); if (input == Confirm) { practice(g->turn, "electronics", (100 - chance_of_success) * 1.5); practice(g->turn, "firstaid", (100 - chance_of_success) * 1.0); practice(g->turn, "mechanics", (100 - chance_of_success) * 0.5); int success = chance_of_success - rng(1, 100); if (success > 0) { g->add_msg("Successfully installed batteries."); max_power_level += pow_up; } else bionics_install_failure(g, this, success); werase(w); delwin(w); g->refresh_all(); return true; } werase(w); delwin(w); g->refresh_all(); return false; }
static void db_show_value (float val, db_show_t *db , int idx) { float h; int pos,minpos,maxpos; float delta; float dist; float minval,maxval; PANEL *sliderp = db->slider_p[idx]; WINDOW *bar_win = panel_window (db->bar_p[idx]); WINDOW *sliderw = panel_window (sliderp); minval = -12.00; maxval = 24.00; minpos = 2; maxpos = getmaxy (bar_win) - 1; h = getmaxy (bar_win) - 1; if (val <= minval) { pos = minpos; } else if (val >= maxval) { pos = maxpos; } else { dist = fabsf (val - minval); delta = fabsf (maxval - minval); pos = floor ((h/delta) * dist); } if (pos <= minpos) { pos = minpos; } if (pos >= maxpos) { pos = maxpos; } wattron (sliderw,COLOR_PAIR (8)); if (val>=0) { mvwprintw (sliderw,0,0,"+"); } else { mvwprintw (sliderw,0,0,"-"); } mvwprintw (sliderw,0,1,"%4.1fdB",fabsf(val)); wattroff (sliderw,COLOR_PAIR (8)); move_panel (sliderp,getbegy (bar_win) + getmaxy (bar_win) - pos,getbegx (sliderw)); update_panels (); doupdate (); return; }
this->win = newwin(sizeY,sizeX,startY,startX); box(this->win,0,0); this->input = ncu_inputString_init_NewString(startX+1,startY+2,sizeX-2); ncu_inputString_changeFunctionChar(this->input , &ncu_fileSelect_acceptchar ); return this; } void ncu_fileSelect_getUart(ncu_fileSelect * this,ncu_cmdLine * cmdp){ if(this->uart != NULL) return; char name[30]; mvwprintw(this->win,1,getmaxx(this->win)/2-2,"UART"); mvwprintw(this->win,2,getmaxx(this->win)/2-2,"DEST"); mvwin(this->input->win,getbegy(this->win)+3,getbegx(this->win)+1); ncu_inputString_changeCible(this->input,name,30); ncu_inputString_clean_string(this->input); strcpy(name,"/dev/ttyUSB0"); wrefresh(this->win); ncu_inputString_action(this->input,cmdp); this->uart = uart_init(this->input->tab); } void ncu_fileSelect_getFIle(ncu_fileSelect * this, ncu_cmdLine * cmdp,int opt){ char name[30]; char dest[30]; mvwprintw(this->win,1,getmaxx(this->win)/2-2,"NAME");
/* * This program demonstrates the Cdk buttonbox widget. */ int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKBUTTONBOX *buttonWidget = 0; CDKENTRY *entry = 0; WINDOW *cursesWin = 0; const char *buttons[] = { " OK ", " Cancel " }; char *info = 0; int selection; /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); /* Start color. */ initCDKColor (); /* Create the entry widget. */ entry = newCDKEntry (cdkscreen, CENTER, CENTER, "<C>Enter a name", "Name ", A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); if (entry == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create entry-widget\n"); ExitProgram (EXIT_FAILURE); } /* Create the button box widget. */ buttonWidget = newCDKButtonbox (cdkscreen, getbegx (entry->win), getbegy (entry->win) + entry->boxHeight - 1, 1, entry->boxWidth - 1, 0, 1, 2, (CDK_CSTRING2) buttons, 2, A_REVERSE, TRUE, FALSE); if (buttonWidget == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create buttonbox-widget\n"); ExitProgram (EXIT_FAILURE); } /* Set the lower left and right characters of the box. */ setCDKEntryLLChar (entry, ACS_LTEE); setCDKEntryLRChar (entry, ACS_RTEE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * Bind the Tab key in the entry field to send a * Tab key to the button box widget. */ bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget); /* Activate the entry field. */ drawCDKButtonbox (buttonWidget, TRUE); info = copyChar (activateCDKEntry (entry, 0)); selection = buttonWidget->currentButton; /* Clean up. */ destroyCDKButtonbox (buttonWidget); destroyCDKEntry (entry); destroyCDKScreen (cdkscreen); endCDK (); printf ("You typed in (%s) and selected button (%s)\n", (info != 0) ? info : "<null>", buttons[selection]); freeChar (info); ExitProgram (EXIT_SUCCESS); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKSLIDER *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype *holder = 0; chtype fieldAttr = A_REVERSE | ' '; int answer = 0; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2, tmp; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *barAttribute; char *buttons; char *label; char *outputFile; char *title; int fieldWidth; int incrementStep; int acceleratedStep; int initValue; int lowValue; int highValue; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "a:f:h:i:l:s:B:F:L:O:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); acceleratedStep = CDKparamValue (¶ms, 'a', -1); fieldWidth = CDKparamValue (¶ms, 'f', 0); highValue = CDKparamValue (¶ms, 'h', INT_MIN); incrementStep = CDKparamValue (¶ms, 'i', 1); lowValue = CDKparamValue (¶ms, 'l', INT_MAX); initValue = CDKparamValue (¶ms, 's', INT_MIN); buttons = CDKparamString (¶ms, 'B'); barAttribute = CDKparamString (¶ms, 'F'); label = CDKparamString (¶ms, 'L'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); incrementStep = abs (incrementStep); /* Make sure all the command line parameters were provided. */ if (fieldWidth <= 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Make sure the user supplied the low/high values. */ if ((lowValue == INT_MAX) || (highValue == INT_MIN)) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Make sure the low is lower than the high (and vice versa). */ if (lowValue > highValue) { tmp = lowValue; lowValue = highValue; highValue = tmp; } /* Make sure the starting value is in range. */ if (initValue < lowValue) { initValue = lowValue; } else if (initValue > highValue) { initValue = highValue; } /* Check if the accelerated incremnt value was set. */ if (acceleratedStep <= 0) { acceleratedStep = (int)((highValue - lowValue) / 10); acceleratedStep = MAXIMUM (1, acceleratedStep); } /* Set up CDK. */ cursesWindow = initscr (); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* Did the user ask to change the bar attribute? */ if (barAttribute != 0) { holder = char2Chtype (barAttribute, &j1, &j2); fieldAttr = holder[0]; freeChtype (holder); } /* Create the entry widget. */ widget = newCDKSlider (cdkScreen, xpos, ypos, title, label, fieldAttr, fieldWidth, initValue, lowValue, highValue, incrementStep, acceleratedStep, boxWidget, shadowWidget); /* Check to make sure we created the dialog box. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Could not create the numeric slider field. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, 0, 1, buttonCount, (CDK_CSTRING2) buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); CDKfreeStrings (buttonList); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKSliderLLChar (widget, ACS_LTEE); setCDKSliderLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vSLIDER, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vSLIDER, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vSLIDER, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKSlider (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKSliderBackgroundColor (widget, CDK_WIDGET_COLOR); /* Activate the widget. */ answer = activateCDKSlider (widget, 0); /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKSlider (widget); destroyCDKScreen (cdkScreen); endCDK (); /* Print the value from the widget. */ fprintf (fp, "%d\n", answer); fclose (fp); /* Exit with the button selected. */ ExitProgram (selection); }
EIF_INTEGER c_ecurses_getbegy (EIF_POINTER w) { return getbegy(((WINDOW *)w)); };
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKTEMPLATE *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; char *answer = 0; char *tmp = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype *holder = 0; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2; CDK_PARAMS params; boolean boxWidget; boolean mixPlate; boolean shadowWidget; char *buttons; char *defaultAnswer; char *label; char *my_overlay; char *outputFile; char *plate; char *title; int minimum; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "d:m:o:p:B:L:O:P:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); minimum = CDKparamValue (¶ms, 'm', 0); mixPlate = CDKparamValue (¶ms, 'P', FALSE); defaultAnswer = CDKparamString (¶ms, 'd'); my_overlay = CDKparamString (¶ms, 'o'); plate = CDKparamString (¶ms, 'p'); buttons = CDKparamString (¶ms, 'B'); label = CDKparamString (¶ms, 'L'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); /* Make sure all the command line parameters were provided. */ if (plate == 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Set up CDK. */ cursesWindow = initscr (); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* Create the template widget. */ widget = newCDKTemplate (cdkScreen, xpos, ypos, title, label, plate, my_overlay, boxWidget, shadowWidget); /* Check to make sure we created the widget. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Could not create the template field. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, 0, 1, buttonCount, (CDK_CSTRING2) buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKTemplateLLChar (widget, ACS_LTEE); setCDKTemplateLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vTEMPLATE, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vTEMPLATE, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vTEMPLATE, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKTemplate (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKTemplateBackgroundColor (widget, CDK_WIDGET_COLOR); /* If a default answer were proivded, set it in the widget. */ if (defaultAnswer != 0) { setCDKTemplateValue (widget, defaultAnswer); } /* If the user asked for a minimum value, set it. */ setCDKTemplateMin (widget, minimum); /* Activate the widget. */ tmp = activateCDKTemplate (widget, 0); /* If the user asked for plate mixing, give it to them. */ if (mixPlate == TRUE) { answer = mixCDKTemplate (widget); } else { answer = copyChar (tmp); } /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKTemplate (widget); destroyCDKScreen (cdkScreen); endCDK (); /* Print the value from the widget. */ if (answer != 0) { fprintf (fp, "%s\n", answer); freeChar (answer); } fclose (fp); /* Exit with the button number picked. */ ExitProgram (selection); }