/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *prompt, const void *selected, int *s_scroll) { int i, j, x, y, box_x, box_y; int height, width, menu_height; int key = 0, button = 0, scroll = 0, choice = 0; int first_item = 0, max_choice; WINDOW *dialog, *menu; do_resize: height = getmaxy(stdscr); width = getmaxx(stdscr); if (height < 15 || width < 65) return -ERRDISPLAYTOOSMALL; height -= 4; width -= 5; menu_height = height - 10; max_choice = MIN(menu_height, item_count()); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); (void)wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); (void)wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); (void)wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad(menu, TRUE); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, dlg.menubox_border.atr, dlg.menubox.atr); if (menu_width >= 80) item_x = (menu_width - 70) / 2; else item_x = 4; /* Set choice to default item */ item_foreach() if (selected && (selected == item_data())) choice = item_n(); /* get the saved scroll info */ scroll = *s_scroll; if ((scroll <= choice) && (scroll + max_choice > choice) && (scroll >= 0) && (scroll + max_choice <= item_count())) { first_item = scroll; choice = choice - scroll; } else { scroll = 0; } if ((choice >= max_choice)) { if (choice >= item_count() - max_choice / 2) scroll = first_item = item_count() - max_choice; else scroll = first_item = choice - max_choice / 2; choice = choice - scroll; } /* Print the menu */ for (i = 0; i < max_choice; i++) { print_item(first_item + i, i, i == choice); } wnoutrefresh(menu); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); print_buttons(dialog, height, width, 0); wmove(menu, choice, item_x + 1); wrefresh(menu); while (key != KEY_ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { /* Remove highligt of current item */ print_item(scroll + choice, choice, FALSE); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item(scroll+choice, choice, FALSE); if ((choice > max_choice - 3) && (scroll + max_choice < item_count())) { /* Scroll menu up */ do_scroll(menu, &scroll, 1); print_item(scroll+max_choice - 1, max_choice - 1, FALSE); } else choice = MIN(choice + 1, max_choice - 1); } else if (key == KEY_PPAGE) { scrollok(menu, TRUE); for (i = 0; (i < max_choice); i++) { if (scroll > 0) { do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else { if (choice > 0) choice--; } } } else if (key == KEY_NPAGE) { for (i = 0; (i < max_choice); i++) { if (scroll + max_choice < item_count()) { do_scroll(menu, &scroll, 1); print_item(scroll+max_choice-1, max_choice - 1, FALSE); } else { if (choice + 1 < max_choice) choice++; } } } else choice = i; print_item(scroll + choice, choice, TRUE); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); wnoutrefresh(dialog); wrefresh(menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': case 'h': case '?': case 'z': case '\n': /* save scroll info */ *s_scroll = scroll; delwin(menu); delwin(dialog); item_set(scroll + choice); item_set_selected(1); switch (key) { case 'h': case '?': return 2; case 's': case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; case 'z': return 8; case '\n': return button; } return 0; case 'e': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(menu); break; case KEY_RESIZE: on_key_resize(); delwin(menu); delwin(dialog); goto do_resize; } } delwin(menu); delwin(dialog); return key; /* ESC pressed */ }
void ActivityActionCanvas::draw(QPainter & p) { if (! visible()) return; QRect r = rect(); QBrush brsh = p.brush(); QColor bckgrnd = p.backgroundColor(); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); QColor co = color(used_color); p.setBackgroundColor(co); const ActivityActionData * data = (ActivityActionData *) browser_node->get_data(); const int shadow = the_canvas()->shadow(); int margin; FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); switch (data->get_action_kind()) { case UmlAcceptEventAction: if (((AcceptEventAction *) data->get_action())->timeevent) { // don't draw shadow margin = (int) (21 * the_canvas()->zoom()); int t = (r.y() + r.bottom() - margin)/2; p.setPen(::Qt::SolidLine); p.setBackgroundMode(::Qt::TransparentMode); p.drawLine(r.right() - margin, t, r.right() - 1, t); p.lineTo(r.right() - margin - 1, t + margin); p.lineTo(r.right() - 1, t + margin); p.lineTo(r.right() - margin - 1, t); if (fp != 0) { fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.right() - margin, t, r.right() - 1, t); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.right() - 1, t, r.right() - margin - 1, t + margin); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.right() - margin - 1, t + margin, r.right() - 1, t + margin); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.right() - 1, t + margin, r.right() - margin - 1, t); } r.setWidth(r.width() - margin - 1); margin = (int) (3 * the_canvas()->zoom()); } else { if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } margin = ((r.height() < r.width()) ? r.height() : r.width()) / 4; QPointArray a(6); a.setPoint(0, r.x(), r.y()); a.setPoint(1, r.right(), r.y()); a.setPoint(2, r.right(), r.bottom()); a.setPoint(3, r.x(), r.bottom()); a.setPoint(4, r.x() + margin, (r.y() + r.bottom())/2); a.setPoint(5, r.x(), r.y()); if (used_color == UmlTransparent) { p.drawPolyline(a); if (fp != 0) draw_poly(fp, a, UmlTransparent); } else { if (shadow != 0) { QPointArray b(6); b.setPoint(0, r.x() + shadow, r.y() + shadow); b.setPoint(1, r.right() + shadow, r.y() + shadow); b.setPoint(2, r.right() + shadow, r.bottom() + shadow); b.setPoint(3, r.x() + shadow, r.bottom() + shadow); b.setPoint(4, r.x() + margin + shadow, (r.y() + r.bottom())/2 + shadow); b.setPoint(5, r.x() + shadow, r.y() + shadow); p.setBrush(::Qt::darkGray); p.setPen(::Qt::NoPen); p.drawPolygon(b, TRUE, 0, 5); p.setPen(::Qt::SolidLine); if (fp != 0) draw_shadow(fp, b); } p.setBrush(co); p.drawPolygon(a, TRUE, 0, 5); if (fp != 0) draw_poly(fp, a, used_color); } r.setLeft(r.left() + margin); margin = (int) (6 * the_canvas()->zoom()); } break; case UmlSendSignalAction: case UmlBroadcastSignalAction: { if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } margin = ((r.height() < r.width()) ? r.height() : r.width()) / 4; QPointArray a(6); a.setPoint(0, r.x(), r.y()); a.setPoint(1, r.right() - margin, r.y()); a.setPoint(2, r.right(), (r.y() + r.bottom())/2); a.setPoint(3, r.right() - margin, r.bottom()); a.setPoint(4, r.x(), r.bottom()); a.setPoint(5, r.x(), r.y()); if (used_color == UmlTransparent) { p.drawPolyline(a); if (fp != 0) draw_poly(fp, a, UmlTransparent); } else { if (shadow != 0) { QPointArray b(6); b.setPoint(0, r.x() + shadow, r.y() + shadow); b.setPoint(1, r.right() - margin + shadow, r.y() + shadow); b.setPoint(2, r.right() + shadow, (r.y() + r.bottom())/2 + shadow); b.setPoint(3, r.right() - margin + shadow, r.bottom() + shadow); b.setPoint(4, r.x() + shadow, r.bottom() + shadow); b.setPoint(5, r.x() + shadow, r.y() + shadow); p.setBrush(::Qt::darkGray); p.setPen(::Qt::NoPen); p.drawPolygon(b, TRUE, 0, 5); p.setPen(::Qt::SolidLine); if (fp != 0) draw_shadow(fp, b); } p.setBrush(co); p.drawPolygon(a, TRUE, 0, 5); if (fp != 0) draw_poly(fp, a, used_color); } r.setWidth(r.width() - margin); margin = (int) (6 * the_canvas()->zoom()); } break; default: margin = (int) (9 * the_canvas()->zoom()); if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); p.setPen(::Qt::NoPen); p.setBrush(::Qt::darkGray); p.drawRoundRect(r.left() + shadow, r.top() + shadow, r.width(), r.height()); if (fp != 0) fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"10\" />\n", ::Qt::darkGray.rgb()&0xffffff, r.left() + shadow, r.top() + shadow, r.width() - 1, r.height() - 1); p.setPen(::Qt::SolidLine); } p.setBrush(co); p.drawRoundRect(r); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"10\" />\n", svg_color(used_color), r.left(), r.top(), r.width() - 1, r.height() - 1); if (data->get_action_kind() == UmlCallBehaviorAction) { BrowserNode * behavior = ((CallBehaviorAction *) data->get_action())->behavior; if ((behavior != 0) && (behavior->get_type() == UmlActivity)) { int l = (int) (6 * the_canvas()->zoom()); int lx = r.right() - margin - l; int ty = r.bottom() - margin - l; int mx = lx + l; int my = ty + l; int rx = mx + l; int by = my + l; p.drawLine(lx, my, rx, my); p.drawLine(mx, ty, mx, by); p.drawLine(lx, my, lx, by); p.drawLine(rx, my, rx, by); if (fp != 0) { fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", lx, my, rx, my); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", mx, ty, mx, by); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", lx, my, lx, by); fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", rx, my, rx, by); } } } break; } p.setFont(the_canvas()->get_font(UmlNormalFont)); p.drawText(r.x() + margin, r.y() + margin, r.width() - margin - margin, r.height() - margin - margin, align, s); if (fp != 0) { fputs("</g>\n", fp); draw_text(r.x() + margin, r.y() + margin, r.width() - margin - margin, r.height() - margin - margin, align, s, p.font(), fp); } p.setBackgroundColor(bckgrnd); p.setBrush(brsh); if (selected()) show_mark(p, rect()); }
/* * Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */ int dialog_checklist(const char *title, const char *prompt, int height, int width, int list_height) { int i, x, y, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice; WINDOW *dialog, *list; /* which item to highlight */ item_foreach() { if (item_is_tag('X')) choice = item_n(); if (item_is_selected()) { choice = item_n(); break; } } do_resize: if (getmaxy(stdscr) < (height + 6)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) < (width + 6)) return -ERRDISPLAYTOOSMALL; max_choice = MIN(list_height, item_count()); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, dlg.menubox_border.atr, dlg.menubox.atr); /* Find length of longest item in order to center checklist */ check_x = 0; item_foreach() check_x = MAX(check_x, strlen(item_str()) + 4); check_x = (list_width - check_x) / 2; item_x = check_x + 4; if (choice >= list_height) { scroll = choice - list_height + 1; choice -= scroll; } /* Print the list */ for (i = 0; i < max_choice; i++) { item_set(scroll + i); print_item(list, i, i == choice); } print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); print_buttons(dialog, height, width, 0); wnoutrefresh(dialog); wnoutrefresh(list); doupdate(); while (key != KEY_ESC) { key = wgetch(dialog); for (i = 0; i < max_choice; i++) { item_set(i + scroll); if (toupper(key) == toupper(item_str()[0])) break; } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) continue; /* Scroll list down */ if (list_height > 1) { /* De-highlight current first item */ item_set(scroll); print_item(list, 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; item_set(scroll); print_item(list, 0, TRUE); print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice - 1; } else if (key == KEY_DOWN || key == '+') { if (choice == max_choice - 1) { if (scroll + choice >= item_count() - 1) continue; /* Scroll list up */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ item_set(scroll + max_choice - 1); print_item(list, max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scroll++; item_set(scroll + max_choice - 1); print_item(list, max_choice - 1, TRUE); print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice + 1; } if (i != choice) { /* De-highlight current item */ item_set(scroll + choice); print_item(list, choice, FALSE); /* Highlight new item */ choice = i; item_set(scroll + choice); print_item(list, choice, TRUE); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case 'H': case 'h': case '?': button = 1; /* fall-through */ case 'S': case 's': case ' ': case '\n': item_foreach() item_set_selected(0); item_set(scroll + choice); item_set_selected(1); delwin(list); delwin(dialog); return button; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case 'X': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(list); delwin(dialog); on_key_resize(); goto do_resize; } /* Now, update everything... */ doupdate(); } delwin(list); delwin(dialog); return key; /* ESC pressed */ }
/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *prompt, int height, int width, int menu_height, const char *current, int item_no, const char *const *items) { int i, j, x, y, box_x, box_y; int key = 0, button = 0, scroll = 0, choice = 0; int first_item = 0, max_choice; WINDOW *dialog, *menu; FILE *f; max_choice = MIN(menu_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); wbkgdset(dialog, dialog_attr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad(menu, TRUE); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, menubox_border_attr, menubox_attr); item_x = (menu_width - 70) / 2; /* Set choice to default item */ for (i = 0; i < item_no; i++) if (strcmp(current, items[i * 2]) == 0) choice = i; /* get the scroll info from the temp file */ if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && (scroll + max_choice > choice) && (scroll >= 0) && (scroll + max_choice <= item_no)) { first_item = scroll; choice = choice - scroll; fclose(f); } else { scroll = 0; remove("lxdialog.scrltmp"); fclose(f); f = NULL; } } if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { if (choice >= item_no - max_choice / 2) scroll = first_item = item_no - max_choice; else scroll = first_item = choice - max_choice / 2; choice = choice - scroll; } /* Print the menu */ for (i = 0; i < max_choice; i++) { print_item(first_item + i, i, i == choice); } wnoutrefresh(menu); print_arrows(dialog, item_no, scroll, box_y, box_x + item_x + 1, menu_height); print_buttons(dialog, height, width, 0); wmove(menu, choice, item_x + 1); wrefresh(menu); while (key != ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) { j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); if (key == tolower(items[(scroll + i) * 2 + 1][j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); if (key == tolower(items[(scroll + i) * 2 + 1][j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { /* Remove highligt of current item */ print_item(scroll + choice, choice, FALSE); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item(scroll+choice, choice, FALSE); if ((choice > max_choice - 3) && (scroll + max_choice < item_no)) { /* Scroll menu up */ do_scroll(menu, &scroll, 1); print_item(scroll+max_choice - 1, max_choice - 1, FALSE); } else choice = MIN(choice + 1, max_choice - 1); } else if (key == KEY_PPAGE) { scrollok(menu, TRUE); for (i = 0; (i < max_choice); i++) { if (scroll > 0) { do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else { if (choice > 0) choice--; } } } else if (key == KEY_NPAGE) { for (i = 0; (i < max_choice); i++) { if (scroll + max_choice < item_no) { do_scroll(menu, &scroll, 1); print_item(scroll+max_choice-1, max_choice - 1, FALSE); } else { if (choice + 1 < max_choice) choice++; } } } else choice = i; print_item(scroll + choice, choice, TRUE); print_arrows(dialog, item_no, scroll, box_y, box_x + item_x + 1, menu_height); wnoutrefresh(dialog); wrefresh(menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': /* save scroll info */ if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { fprintf(f, "%d\n", scroll); fclose(f); } delwin(dialog); fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); switch (key) { case 's': return 3; case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; } return 0; case 'h': case '?': button = 2; case '\n': delwin(dialog); if (button == 2) fprintf(stderr, "%s \"%s\"\n", items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1] + first_alpha(items [(scroll + choice) * 2 + 1], "")); else fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); remove("lxdialog.scrltmp"); return button; case 'e': case 'x': key = ESC; case ESC: break; } } delwin(dialog); remove("lxdialog.scrltmp"); return -1; /* ESC presgsed */ }
/* * Display text from a file in a dialog box. */ int dialog_textbox(const char *title, const char *tbuf, int initial_height, int initial_width) { int i, x, y, cur_x, cur_y, key = 0; int height, width, boxh, boxw; int passed_end; WINDOW *dialog, *box; begin_reached = 1; end_reached = 0; page_length = 0; hscroll = 0; buf = tbuf; page = buf; /* page is pointer to start of page to be displayed */ do_resize: getmaxyx(stdscr, height, width); if (height < 8 || width < 8) return -ERRDISPLAYTOOSMALL; if (initial_height != 0) height = initial_height; else if (height > 4) height -= 4; else height = 0; if (initial_width != 0) width = initial_width; else if (width > 5) width -= 5; else width = 0; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); /* Create window for box region, used for scrolling text */ boxh = height - 4; boxw = width - 2; box = subwin(dialog, boxh, boxw, y + 1, x + 1); wattrset(box, dlg.dialog.atr); wbkgdset(box, dlg.dialog.atr & A_COLOR); keypad(box, TRUE); /* register the new window, along with its borders */ draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE); wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear(box, boxh, boxw, dlg.dialog.atr); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); while ((key != KEY_ESC) && (key != '\n')) { key = wgetch(dialog); switch (key) { case 'E': /* Exit */ case 'e': case 'X': case 'x': delwin(box); delwin(dialog); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; page = buf; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); } break; case 'G': /* Last page */ case KEY_END: end_reached = 1; /* point to last char in buf */ page = buf + strlen(buf); back_lines(boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines(page_length + 1); /* We don't call print_page() here but use * scrolling to ensure faster screen update. * However, 'end_reached' and 'page_length' * should still be updated, and 'page' should * point to start of next page. This is done * by calling get_line() in the following * 'for' loop. */ scrollok(box, TRUE); wscrl(box, -1); /* Scroll box region down one line */ scrollok(box, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < boxh; i++) { if (!i) { /* print first line of page */ print_line(box, 0, boxw); wnoutrefresh(box); } else /* Called to update 'end_reached' and 'page' */ get_line(); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines(page_length + boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok(box, TRUE); scroll(box); /* Scroll box region up one line */ scrollok(box, FALSE); print_line(box, boxh - 1, boxw); wnoutrefresh(box); print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case KEY_NPAGE: /* Next page */ case ' ': if (end_reached) break; begin_reached = 0; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll <= 0) break; if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll >= MAX_LEN) break; hscroll++; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: back_lines(height); delwin(box); delwin(dialog); on_key_resize(); goto do_resize; } } delwin(box); delwin(dialog); return key; /* ESC pressed */ }
/* * Display a dialog box for inputing a string */ int dialog_inputbox(const char *title, const char *prompt, int height, int width, const char *init) { int i, x, y, box_y, box_x, box_width; int input_x = 0, scroll = 0, key = 0, button = -1; char *instr = dialog_input_result; WINDOW *dialog; if (!init) instr[0] = '\0'; else strcpy(instr, init); do_resize: if (getmaxy(stdscr) <= (height - 2)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) <= (width - 2)) return -ERRDISPLAYTOOSMALL; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); (void)wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); (void)wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); (void)wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); /* Draw the input field box */ box_width = width - 6; getyx(dialog, y, x); box_y = y + 2; box_x = (width - box_width) / 2; draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, dlg.dialog.atr, dlg.border.atr); print_buttons(dialog, height, width, 0); /* Set up the initial value */ wmove(dialog, box_y, box_x); (void)wattrset(dialog, dlg.inputbox.atr); input_x = strlen(instr); if (input_x >= box_width) { scroll = input_x - box_width + 1; input_x = box_width - 1; for (i = 0; i < box_width - 1; i++) waddch(dialog, instr[scroll + i]); } else { waddstr(dialog, instr); } wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); while (key != KEY_ESC) { key = wgetch(dialog); if (button == -1) { /* Input box selected */ switch (key) { case TAB: case KEY_UP: case KEY_DOWN: break; case KEY_LEFT: continue; case KEY_RIGHT: continue; case KEY_BACKSPACE: case 127: if (input_x || scroll) { (void)wattrset(dialog, dlg.inputbox.atr); if (!input_x) { scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); wmove(dialog, box_y, box_x); for (i = 0; i < box_width; i++) waddch(dialog, instr[scroll + input_x + i] ? instr[scroll + input_x + i] : ' '); input_x = strlen(instr) - scroll; } else input_x--; instr[scroll + input_x] = '\0'; mvwaddch(dialog, box_y, input_x + box_x, ' '); wmove(dialog, box_y, input_x + box_x); wrefresh(dialog); } continue; default: if (key < 0x100 && isprint(key)) { if (scroll + input_x < MAX_LEN) { (void)wattrset(dialog, dlg.inputbox.atr); instr[scroll + input_x] = key; instr[scroll + input_x + 1] = '\0'; if (input_x == box_width - 1) { scroll++; wmove(dialog, box_y, box_x); for (i = 0; i < box_width - 1; i++) waddch(dialog, instr [scroll + i]); } else { wmove(dialog, box_y, input_x++ + box_x); waddch(dialog, key); } wrefresh(dialog); } else flash(); /* Alarm user about overflow */ continue; } } } switch (key) { case 'O': case 'o': delwin(dialog); return 0; case 'H': case 'h': delwin(dialog); return 1; case KEY_UP: case KEY_LEFT: switch (button) { case -1: button = 1; /* Indicates "Help" button is selected */ print_buttons(dialog, height, width, 1); break; case 0: button = -1; /* Indicates input box is selected */ print_buttons(dialog, height, width, 0); wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); break; case 1: button = 0; /* Indicates "OK" button is selected */ print_buttons(dialog, height, width, 0); break; } break; case TAB: case KEY_DOWN: case KEY_RIGHT: switch (button) { case -1: button = 0; /* Indicates "OK" button is selected */ print_buttons(dialog, height, width, 0); break; case 0: button = 1; /* Indicates "Help" button is selected */ print_buttons(dialog, height, width, 1); break; case 1: button = -1; /* Indicates input box is selected */ print_buttons(dialog, height, width, 0); wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); break; } break; case ' ': case '\n': delwin(dialog); return (button == -1 ? 0 : button); case 'X': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(dialog); on_key_resize(); goto do_resize; } } delwin(dialog); return KEY_ESC; /* ESC pressed */ }
/* * Display a dialog box with two buttons - Yes and No */ int dialog_yesno(const char *title, const char *prompt, int height, int width) { int i, x, y, key = 0, button = 0; WINDOW *dialog; do_resize: if (getmaxy(stdscr) < (height + 4)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) < (width + 4)) return -ERRDISPLAYTOOSMALL; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); print_buttons(dialog, height, width, 0); while (key != KEY_ESC) { key = wgetch(dialog); switch (key) { case 'Y': case 'y': delwin(dialog); return 0; case 'N': case 'n': delwin(dialog); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case ' ': case '\n': delwin(dialog); return button; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(dialog); on_key_resize(); goto do_resize; } } delwin(dialog); return key; /* ESC pressed */ }
void setup_tile (gint w, gint h) { cairo_status_t status; cairo_t* cr = NULL; cairo_surface_t* cr_surf = NULL; cairo_surface_t* tmp = NULL; cairo_surface_t* dummy_surf = NULL; cairo_surface_t* norm_surf = NULL; cairo_surface_t* blur_surf = NULL; gdouble width = (gdouble) w; gdouble height = (gdouble) h; raico_blur_t* blur = NULL; cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 3 * BUBBLE_SHADOW_SIZE, 3 * BUBBLE_SHADOW_SIZE); status = cairo_surface_status (cr_surf); if (status != CAIRO_STATUS_SUCCESS) g_print ("Error: \"%s\"\n", cairo_status_to_string (status)); cr = cairo_create (cr_surf); status = cairo_status (cr); if (status != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (cr_surf); g_print ("Error: \"%s\"\n", cairo_status_to_string (status)); } // clear and render drop-shadow and bubble-background cairo_scale (cr, 1.0f, 1.0f); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); if (g_composited) { draw_shadow (cr, width, height, BUBBLE_SHADOW_SIZE, CORNER_RADIUS); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); draw_round_rect (cr, 1.0f, (gdouble) BUBBLE_SHADOW_SIZE, (gdouble) BUBBLE_SHADOW_SIZE, (gdouble) CORNER_RADIUS, (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE), (gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE)); cairo_fill (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, BUBBLE_BG_COLOR_R, BUBBLE_BG_COLOR_G, BUBBLE_BG_COLOR_B, 0.95f); } else cairo_set_source_rgb (cr, BUBBLE_BG_COLOR_R, BUBBLE_BG_COLOR_G, BUBBLE_BG_COLOR_B); draw_round_rect (cr, 1.0f, BUBBLE_SHADOW_SIZE, BUBBLE_SHADOW_SIZE, CORNER_RADIUS, (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE), (gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE)); cairo_fill (cr); tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (cr_surf), cairo_image_surface_get_format (cr_surf), 3 * BUBBLE_SHADOW_SIZE, 3 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (cr_surf)); dummy_surf = copy_surface (tmp); cairo_surface_destroy (tmp); tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (dummy_surf), cairo_image_surface_get_format (dummy_surf), 2 * BUBBLE_SHADOW_SIZE, 2 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (dummy_surf)); norm_surf = copy_surface (tmp); cairo_surface_destroy (tmp); blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW); raico_blur_set_radius (blur, 6); raico_blur_apply (blur, dummy_surf); raico_blur_destroy (blur); tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (dummy_surf), cairo_image_surface_get_format (dummy_surf), 2 * BUBBLE_SHADOW_SIZE, 2 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (dummy_surf)); blur_surf = copy_surface (tmp); cairo_surface_destroy (tmp); cairo_surface_destroy (dummy_surf); g_tile = tile_new_for_padding (norm_surf, blur_surf); cairo_surface_destroy (norm_surf); cairo_surface_destroy (blur_surf); cairo_surface_destroy (cr_surf); cairo_destroy (cr); }
/* * Display text from a file in a dialog box. */ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width) { int i, x, y, cur_x, cur_y, fpos, key = 0, dir, temp, temp1; #ifdef HAVE_NCURSES int passed_end; #endif unsigned char search_term[MAX_LEN+1], *tempptr, *found; WINDOW *dialog, *text; if (height < 0 || width < 0) { fprintf(stderr, "\nAutosizing is impossible in dialog_textbox().\n"); return(-1); } search_term[0] = '\0'; /* no search term entered yet */ /* Open input file for reading */ if ((fd = open(file, O_RDONLY)) == -1) { fprintf(stderr, "\nCan't open input file <%s>in dialog_textbox().\n", file); return(-1); } /* Get file size. Actually, 'file_size' is the real file size - 1, since it's only the last byte offset from the beginning */ if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { fprintf(stderr, "\nError getting file size in dialog_textbox().\n"); return(-1); } /* Restore file pointer to beginning of file after getting file size */ if (lseek(fd, 0, SEEK_SET) == -1) { fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); return(-1); } /* Allocate space for read buffer */ if ((buf = malloc(BUF_SIZE+1)) == NULL) { endwin(); fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n"); exit(-1); } if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { fprintf(stderr, "\nError reading file in dialog_textbox().\n"); return(-1); } buf[bytes_read] = '\0'; /* mark end of valid data */ page = buf; /* page is pointer to start of page to be displayed */ if (width > COLS) width = COLS; if (height > LINES) height = LINES; /* center dialog box on screen */ x = DialogX ? DialogX : (COLS - width)/2; y = DialogY ? DialogY : (LINES - height)/2; #ifdef HAVE_NCURSES if (use_shadow) draw_shadow(stdscr, y, x, height, width); #endif dialog = newwin(height, width, y, x); if (dialog == NULL) { endwin(); fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x); exit(1); } keypad(dialog, TRUE); /* Create window for text region, used for scrolling text */ /* text = newwin(height-4, width-2, y+1, x+1); */ text = subwin(dialog, height-4, width-2, y+1, x+1); if (text == NULL) { endwin(); fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", height-4,width-2,y+1,x+1); exit(1); } keypad(text, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); wmove(dialog, height-3, 0); waddch(dialog, ACS_LTEE); for (i = 0; i < width-2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); wmove(dialog, height-2, 1); for (i = 0; i < width-2; i++) waddch(dialog, ' '); if (title != NULL) { wattrset(dialog, title_attr); wmove(dialog, 0, (width - strlen(title))/2 - 1); waddch(dialog, ' '); waddstr(dialog, title); waddch(dialog, ' '); } display_helpline(dialog, height-1, width); print_button(dialog, " OK ", height-2, width/2-6, TRUE); wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear(text, height-4, width-2, dialog_attr); print_page(text, height-4, width-2); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); while ((key != ESC) && (key != '\n') && (key != '\r') && (key != ' ')) { key = wgetch(dialog); switch (key) { case 'E': /* Exit */ case 'e': delwin(dialog); free(buf); close(fd); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; /* First page not in buffer? */ if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } if (fpos > bytes_read) { /* Yes, we have to read it in */ if (lseek(fd, 0, SEEK_SET) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { endwin(); fprintf(stderr, "\nError reading file in dialog_textbox().\n"); exit(-1); } buf[bytes_read] = '\0'; } page = buf; print_page(text, height-4, width-2); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'G': /* Last page */ #ifdef HAVE_NCURSES case KEY_END: #endif end_reached = 1; /* Last page not in buffer? */ if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } if (fpos < file_size) { /* Yes, we have to read it in */ if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { endwin(); fprintf(stderr, "\nError reading file in dialog_textbox().\n"); exit(-1); } buf[bytes_read] = '\0'; } page = buf + bytes_read; back_lines(height-4); print_page(text, height-4, width-2); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); break; case 'K': /* Previous line */ case 'k': case '\020': /* ^P */ case KEY_UP: if (!begin_reached) { back_lines(page_length+1); #ifdef HAVE_NCURSES /* We don't call print_page() here but use scrolling to ensure faster screen update. However, 'end_reached' and 'page_length' should still be updated, and 'page' should point to start of next page. This is done by calling get_line() in the following 'for' loop. */ scrollok(text, TRUE); wscrl(text, -1); /* Scroll text region down one line */ scrollok(text, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < height-4; i++) { if (!i) { print_line(text, 0, width-2); /* print first line of page */ wnoutrefresh(text); } else get_line(); /* Called to update 'end_reached' and 'page' */ if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } #else print_page(text, height-4, width-2); #endif print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (!begin_reached) { back_lines(page_length + height-4); print_page(text, height-4, width-2); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'J': /* Next line */ case 'j': case '\016': /* ^N */ case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok(text, TRUE); scroll(text); /* Scroll text region up one line */ scrollok(text, FALSE); print_line(text, height-5, width-2); #ifndef HAVE_NCURSES wmove(text, height-5, 0); waddch(text, ' '); wmove(text, height-5, width-3); waddch(text, ' '); #endif wnoutrefresh(text); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'F': /* Next page */ case 'f': case KEY_NPAGE: if (!end_reached) { begin_reached = 0; print_page(text, height-4, width-2); print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll > 0) { if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines(page_length); print_page(text, height-4, width-2); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll < MAX_LEN) { hscroll++; /* Reprint current page to scroll horizontally */ back_lines(page_length); print_page(text, height-4, width-2); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case '/': /* Forward search */ case 'n': /* Repeat forward search */ case '?': /* Backward search */ case 'N': /* Repeat backward search */ /* set search direction */ dir = (key == '/' || key == 'n') ? 1 : 0; if (dir ? !end_reached : !begin_reached) { if (key == 'n' || key == 'N') { if (search_term[0] == '\0') { /* No search term yet */ fprintf(stderr, "\a"); /* beep */ break; } } else /* Get search term from user */ if (get_search_term(text, search_term, height-4, width-2) == -1) { /* ESC pressed in get_search_term(). Reprint page to clear box */ wattrset(text, dialog_attr); back_lines(page_length); print_page(text, height-4, width-2); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); break; } /* Save variables for restoring in case search term can't be found */ tempptr = page; temp = begin_reached; temp1 = end_reached; if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } fpos -= bytes_read; /* update 'page' to point to next (previous) line before forward (backward) searching */ back_lines(dir ? page_length-1 : page_length+1); found = NULL; if (dir) /* Forward search */ while((found = strstr(get_line(), search_term)) == NULL) { if (end_reached) break; } else /* Backward search */ while((found = strstr(get_line(), search_term)) == NULL) { if (begin_reached) break; back_lines(2); } if (found == NULL) { /* not found */ fprintf(stderr, "\a"); /* beep */ /* Restore program state to that before searching */ if (lseek(fd, fpos, SEEK_SET) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); exit(-1); } if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { endwin(); fprintf(stderr, "\nError reading file in dialog_textbox().\n"); exit(-1); } buf[bytes_read] = '\0'; page = tempptr; begin_reached = temp; end_reached = temp1; /* move 'page' to point to start of current page in order to re-print current page. Note that 'page' always points to start of next page, so this is necessary */ back_lines(page_length); } else /* Search term found */ back_lines(1); /* Reprint page */ wattrset(text, dialog_attr); print_page(text, height-4, width-2); if (found != NULL) print_position(dialog, height, width); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } else /* no need to find */ fprintf(stderr, "\a"); /* beep */ break; case ESC: break; case KEY_F(1): display_helpfile(); break; } } delwin(dialog); free(buf); close(fd); return (key == ESC ? -1 : 0); }
/* * Display a dialog box with a list of options that can be turned on or off */ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int cnt, void *it, unsigned char *result) { int i, j, x, y, cur_x, cur_y, old_x, old_y, box_x, box_y, key = 0, button, choice, l, k, scroll, max_choice, *status, item_no = 0, was_on = 0; int redraw_menu = FALSE, cursor_reset = FALSE; int rval = 0, onlist = 1, ok_space, cancel_space; char okButton, cancelButton; WINDOW *dialog, *list; unsigned char **items = NULL; dialogMenuItem *ditems; /* Allocate space for storing item on/off status */ if ((status = alloca(sizeof(int) * abs(cnt))) == NULL) { endwin(); fprintf(stderr, "\nCan't allocate memory in dialog_radiolist().\n"); exit(-1); } draw: button = choice = scroll = 0; /* Previous calling syntax, e.g. just a list of strings? */ if (cnt >= 0) { items = it; ditems = NULL; item_no = cnt; /* Initializes status */ for (i = 0; i < item_no; i++) { status[i] = !strcasecmp(items[i*3 + 2], "on"); if (status[i]) { if (was_on) status[i] = FALSE; else was_on = 1; } } } /* It's the new specification format - fake the rest of the code out */ else { item_no = abs(cnt); ditems = it; if (!items) items = (unsigned char **)alloca((item_no * 3) * sizeof(unsigned char *)); /* Initializes status */ for (i = 0; i < item_no; i++) { status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE; if (status[i]) { if (was_on) status[i] = FALSE; else was_on = 1; } items[i*3] = ditems[i].prompt; items[i*3 + 1] = ditems[i].title; items[i*3 + 2] = status[i] ? "on" : "off"; } } max_choice = MIN(list_height, item_no); check_x = 0; item_x = 0; /* Find length of longest item in order to center radiolist */ for (i = 0; i < item_no; i++) { l = strlen(items[i * 3]); for (j = 0; j < item_no; j++) { k = strlen(items[j * 3 + 1]); check_x = MAX(check_x, l + k + 6); } item_x = MAX(item_x, l); } if (height < 0) height = strheight(prompt) + list_height + 4 + 2; if (width < 0) { i = strwidth(prompt); j = ((title != NULL) ? strwidth(title) : 0); width = MAX(i, j); width = MAX(width, check_x + 4) + 4; } width = MAX(width, 24); if (width > COLS) width = COLS; if (height > LINES) height = LINES; /* center dialog box on screen */ x = DialogX ? DialogX : (COLS - width) / 2; y = DialogY ? DialogY : (LINES - height) / 2; #ifdef HAVE_NCURSES if (use_shadow) draw_shadow(stdscr, y, x, height, width); #endif dialog = newwin(height, width, y, x); if (dialog == NULL) { endwin(); fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height, width, y, x); return -1; } keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); wmove(dialog, height - 3, 0); waddch(dialog, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); wmove(dialog, height - 2, 1); for (i = 0; i < width - 2; i++) waddch(dialog, ' '); if (title != NULL) { wattrset(dialog, title_attr); wmove(dialog, 0, (width - strlen(title)) / 2 - 1); waddch(dialog, ' '); waddstr(dialog, title); waddch(dialog, ' '); } wattrset(dialog, dialog_attr); wmove(dialog, 1, 2); print_autowrap(dialog, prompt, height - 1, width - 2, width, 1, 2, TRUE, FALSE); list_width = width - 6; getyx(dialog, cur_y, cur_x); box_y = cur_y + 1; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); if (list == NULL) { delwin(dialog); endwin(); fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", list_height, list_width, y + box_y + 1,x + box_x + 1); return -1; } keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height+2, list_width+2, menubox_border_attr, menubox_attr); check_x = (list_width - check_x) / 2; item_x = check_x + item_x + 6; /* Print the list */ for (i = 0; i < max_choice; i++) print_item(list, items[i * 3], items[i * 3 + 1], status[i], i, i == choice, DREF(ditems, i)); wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); display_helpline(dialog, height-1, width); x = width/ 2 - 11; y = height - 2; if (ditems && result) { cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]); print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE); okButton = toupper(ditems[OK_BUTTON].prompt[0]); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE); } else { cancelButton = 'C'; print_button(dialog, "Cancel", y, x + 14, FALSE); okButton = 'O'; print_button(dialog, " OK ", y, x, TRUE); } wnoutrefresh(dialog); wmove(list, choice, check_x+1); wrefresh(list); while (key != ESC) { key = wgetch(dialog); /* See if its the short-cut to "OK" */ if (toupper(key) == okButton) { if (ditems) { if (result && ditems[OK_BUTTON].fire) { int st; WINDOW *save; save = dupwin(newscr); st = ditems[OK_BUTTON].fire(&ditems[OK_BUTTON]); if (st & DITEM_RESTORE) { touchwin(save); wrefresh(save); } delwin(save); } } else if (result) { *result = '\0'; for (i = 0; i < item_no; i++) { if (status[i]) { strcat(result, items[i*3]); break; } } } rval = 0; key = ESC; break; } /* Shortcut to cancel */ if (toupper(key) == cancelButton) { if (ditems && result && ditems[CANCEL_BUTTON].fire) { int st; WINDOW *save; save = dupwin(newscr); st = ditems[CANCEL_BUTTON].fire(&ditems[CANCEL_BUTTON]); if (st & DITEM_RESTORE) { touchwin(save); wrefresh(save); } delwin(save); } rval = 1; key = ESC; break; } /* Check if key pressed matches first character of any item tag in list */ for (i = 0; i < max_choice; i++) if (key != ' ' && toupper(key) == toupper(items[(scroll + i) * 3][0])) break; if (i < max_choice || (key >= '1' && key <= MIN('9', '0' + max_choice)) || KEY_IS_UP(key) || KEY_IS_DOWN(key) || ((key == ' ' || key == '\r' || key == '\n') && onlist == 1)) { /* if moving from buttons to the list, reset and redraw buttons */ if (!onlist) { onlist = 1; button = 0; if (ditems && result ) { print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); } else { print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, " OK ", y, x, !button); } } wmove(list, choice, check_x+1); wnoutrefresh(dialog); wrefresh(list); if (key >= '1' && key <= MIN('9', '0' + max_choice)) i = key - '1'; else if (KEY_IS_UP(key)) { if (!choice) { if (scroll) { /* Scroll list down */ getyx(dialog, cur_y, cur_x); /* Save cursor position */ if (list_height > 1) { /* De-highlight current first item before scrolling down */ print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, FALSE, DREF(ditems, scroll)); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, TRUE, DREF(ditems, scroll)); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); wmove(list, choice, check_x+1); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } else i = choice - 1; } else if (KEY_IS_DOWN(key)) { if (choice == max_choice - 1) { if (scroll + choice < item_no - 1) { /* Scroll list up */ getyx(dialog, cur_y, cur_x); /* Save cursor position */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, FALSE, DREF(ditems, scroll + max_choice - 1)); scrollok(list, TRUE); scroll(list); scrollok(list, FALSE); } scroll++; print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1)); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); wmove(list, choice, check_x+1); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } else i = choice + 1; } else if ((key == ' ' || key == '\r' || key == '\n') && onlist) { /* Toggle item status */ getyx(list, old_y, old_x); /* Save cursor position */ if (status[scroll + choice]) continue; else if (ditems) { if (ditems[scroll + choice].fire) { int st; WINDOW *save; save = dupwin(newscr); st = ditems[scroll + choice].fire(&ditems[scroll + choice]); if (st & DITEM_RESTORE) { touchwin(save); wrefresh(save); } delwin(save); if (st & DITEM_REDRAW) { wclear(list); for (i = 0; i < item_no; i++) status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE; for (i = 0; i < max_choice; i++) { print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice, DREF(ditems, scroll + i)); } /* wmove(list, old_y, old_x);*/ /* Restore cursor to previous position */ /* wrefresh(list); */ } if (st & DITEM_LEAVE_MENU) { /* Allow a fire action to take us out of the menu */ key = ESC; break; } else if (st & DITEM_RECREATE) { delwin(list); delwin(dialog); dialog_clear(); goto draw; } } for (i = 0; i < item_no; i++) status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE; } else { for (i = 0; i < item_no; i++) status[i] = 0; status[scroll + choice] = TRUE; } for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice, DREF(ditems, scroll + i)); wmove(list, choice, check_x+1); /* Restore cursor position */ wrefresh(list); continue; /* wait for another key press */ } if (i != choice) { /* De-highlight current item */ print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 +1], status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice)); /* Highlight new item */ choice = i; print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice)); wmove(list, choice, check_x+1); /* Restore cursor position */ wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case KEY_PPAGE: if (scroll > height-4) /* can we go up? */ scroll -= (height-4); else scroll = 0; redraw_menu = TRUE; if (!onlist) { onlist = 1; button = 0; } break; case KEY_NPAGE: if (scroll + list_height >= item_no-1 - list_height) { /* can we go down a full page? */ scroll = item_no - list_height; if (scroll < 0) scroll = 0; } else scroll += list_height; redraw_menu = TRUE; if (!onlist) { onlist = 1; button = 0; } break; case KEY_HOME: scroll = 0; choice = 0; redraw_menu = TRUE; cursor_reset = TRUE; onlist = 1; break; case KEY_END: scroll = item_no - list_height; if (scroll < 0) scroll = 0; choice = max_choice - 1; redraw_menu = TRUE; cursor_reset = TRUE; onlist = 1; break; case TAB: case KEY_BTAB: /* move to next component */ if (onlist) { /* on list, next is ok button */ onlist = 0; if (ditems && result) ok_space = 1; else ok_space = 3; wmove(dialog, y, x + ok_space); wrefresh(dialog); break; } else if (button) { /* on cancel button, next is list */ button = 0; onlist = 1; redraw_menu = TRUE; break; } /* on ok button, next is cancel button, same as left/right case */ case KEY_LEFT: case KEY_RIGHT: onlist = 0; button = !button; if (ditems && result) { print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); ok_space = 1; cancel_space = strlen(ditems[OK_BUTTON].prompt) + 6; } else { print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, " OK ", y, x, !button); ok_space = 3; cancel_space = 15; } if (button) wmove(dialog, y, x + cancel_space); else wmove(dialog, y, x + ok_space); wrefresh(dialog); break; case ' ': case '\r': case '\n': if (!onlist) { if (ditems) { if (result && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) { int st; WINDOW *save; save = dupwin(newscr); st = ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]); if (st & DITEM_RESTORE) { touchwin(save); wrefresh(save); } delwin(save); } } else if (result) { *result = '\0'; for (i = 0; i < item_no; i++) { if (status[i]) { strcpy(result, items[i*3]); break; } } } rval = button; key = ESC; break; } case ESC: rval = -1; break; case KEY_F(1): case '?': display_helpfile(); break; } if (redraw_menu) { getyx(list, old_y, old_x); wclear(list); for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice, DREF(ditems, scroll + i)); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); /* redraw buttons to fix highlighting */ if (ditems && result) { print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); } else { print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, " OK ", y, x, !button); } wnoutrefresh(dialog); if (cursor_reset) { wmove(list, choice, check_x+1); cursor_reset = FALSE; } else { wmove(list, old_y, old_x); } wrefresh(list); redraw_menu = FALSE; } } delwin(list); delwin(dialog); return rval; /* ESC pressed */ }
void setup_tile (gint w, gint h) { cairo_status_t status; cairo_t* cr = NULL; cairo_surface_t* cr_surf = NULL; gdouble width = (gdouble) w; gdouble height = (gdouble) h; cairo_surface_t* tmp = NULL; cairo_surface_t* dummy_surf = NULL; cairo_surface_t* norm_surf = NULL; cairo_surface_t* blur_surf = NULL; raico_blur_t* blur = NULL; tile_t* tile = NULL; // create tmp. surface for scratch cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 3 * BUBBLE_SHADOW_SIZE, 3 * BUBBLE_SHADOW_SIZE); status = cairo_surface_status (cr_surf); if (status != CAIRO_STATUS_SUCCESS) g_print ("Error: \"%s\"\n", cairo_status_to_string (status)); // create context for that tmp. scratch surface cr = cairo_create (cr_surf); status = cairo_status (cr); if (status != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (cr_surf); g_print ("Error: \"%s\"\n", cairo_status_to_string (status)); } // clear, render drop-shadow and bubble-background in scratch-surface cairo_scale (cr, 1.0f, 1.0f); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); if (g_composited) { draw_shadow (cr, width, height, BUBBLE_SHADOW_SIZE, CORNER_RADIUS); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); draw_round_rect (cr, 1.0f, (gdouble) BUBBLE_SHADOW_SIZE, (gdouble) BUBBLE_SHADOW_SIZE, (gdouble) CORNER_RADIUS, (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE), (gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE)); cairo_fill (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, BUBBLE_BG_COLOR_R, BUBBLE_BG_COLOR_G, BUBBLE_BG_COLOR_B, 0.95f); } else cairo_set_source_rgb (cr, BUBBLE_BG_COLOR_R, BUBBLE_BG_COLOR_G, BUBBLE_BG_COLOR_B); draw_round_rect (cr, 1.0f, BUBBLE_SHADOW_SIZE, BUBBLE_SHADOW_SIZE, CORNER_RADIUS, (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE), (gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE)); cairo_fill (cr); // create tmp. copy of scratch-surface tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (cr_surf), cairo_image_surface_get_format (cr_surf), 3 * BUBBLE_SHADOW_SIZE, 3 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (cr_surf)); dummy_surf = copy_surface (tmp); cairo_surface_destroy (tmp); // create normal-state surface for tile from copy of scratch-surface tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (dummy_surf), cairo_image_surface_get_format (dummy_surf), 2 * BUBBLE_SHADOW_SIZE, 2 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (dummy_surf)); norm_surf = copy_surface (tmp); cairo_surface_destroy (tmp); // blur tmp. copy of scratch-surface blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW); raico_blur_set_radius (blur, 6); raico_blur_apply (blur, dummy_surf); raico_blur_destroy (blur); // create blurred-state surface for tile tmp = cairo_image_surface_create_for_data ( cairo_image_surface_get_data (dummy_surf), cairo_image_surface_get_format (dummy_surf), 2 * BUBBLE_SHADOW_SIZE, 2 * BUBBLE_SHADOW_SIZE, cairo_image_surface_get_stride (dummy_surf)); blur_surf = copy_surface (tmp); cairo_surface_destroy (tmp); // actually create the tile with padding in mind tile = tile_new_for_padding (norm_surf, blur_surf); destroy_cloned_surface (norm_surf); destroy_cloned_surface (blur_surf); destroy_cloned_surface (dummy_surf); cairo_destroy (cr); cairo_surface_destroy (cr_surf); norm_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); cr = cairo_create (norm_surf); cairo_scale (cr, 1.0f, 1.0f); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 1.0f, 0.0f); cairo_destroy (cr); blur_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); cr = cairo_create (blur_surf); cairo_scale (cr, 1.0f, 1.0f); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 0.0f, 1.0f); cairo_destroy (cr); g_tile = tile_new_for_padding (norm_surf, blur_surf); // clean up tile_destroy (tile); cairo_surface_destroy (norm_surf); cairo_surface_destroy (blur_surf); }
/* * Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */ int dialog_checklist(const char *title, const char *prompt, int height, int width, int list_height, int item_no, const char *const *items) { int i, x, y, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; WINDOW *dialog, *list; /* Allocate space for storing item on/off status */ if ((status = malloc(sizeof(int) * item_no)) == NULL) { endwin(); fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n"); exit(-1); } /* Initializes status */ for (i = 0; i < item_no; i++) { status[i] = !strcasecmp(items[i * 3 + 2], "on"); if ((!choice && status[i]) || !strcasecmp(items[i * 3 + 2], "selected")) choice = i + 1; } if (choice) choice--; max_choice = MIN(list_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, menubox_border_attr, menubox_attr); /* Find length of longest item in order to center checklist */ check_x = 0; for (i = 0; i < item_no; i++) check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); check_x = (list_width - check_x) / 2; item_x = check_x + 4; if (choice >= list_height) { scroll = choice - list_height + 1; choice -= scroll; } /* Print the list */ for (i = 0; i < max_choice; i++) { print_item(list, items[(scroll + i) * 3 + 1], status[i + scroll], i, i == choice); } print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); print_buttons(dialog, height, width, 0); wnoutrefresh(dialog); wnoutrefresh(list); doupdate(); while (key != ESC) { key = wgetch(dialog); for (i = 0; i < max_choice; i++) if (toupper(key) == toupper(items[(scroll + i) * 3 + 1][0])) break; if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) continue; /* Scroll list down */ if (list_height > 1) { /* De-highlight current first item */ print_item(list, items[scroll * 3 + 1], status[scroll], 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice - 1; } else if (key == KEY_DOWN || key == '+') { if (choice == max_choice - 1) { if (scroll + choice >= item_no - 1) continue; /* Scroll list up */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scroll++; print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice + 1; } if (i != choice) { /* De-highlight current item */ print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, FALSE); /* Highlight new item */ choice = i; print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case 'H': case 'h': case '?': fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case 'S': case 's': case ' ': case '\n': if (!button) { if (!status[scroll + choice]) { for (i = 0; i < item_no; i++) status[i] = 0; status[scroll + choice] = 1; for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice); } wnoutrefresh(dialog); wrefresh(list); for (i = 0; i < item_no; i++) if (status[i]) fprintf(stderr, "%s", items[i * 3]); } else fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return button; case 'X': case 'x': key = ESC; case ESC: break; } /* Now, update everything... */ doupdate(); } delwin(dialog); free(status); return -1; /* ESC pressed */ }
/* * Display a dialog box with two buttons - Yes and No */ int dialog_yesno (const char *title, const char *prompt, int height, int width) { int i, x, y, key = 0, button = 0; WINDOW *dialog; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); mvwaddch (dialog, height-3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { /* truncate long title -- mec */ char * title2 = malloc(width-2+1); memcpy( title2, title, width-2 ); title2[width-2] = '\0'; title = title2; } if (title != NULL) { wattrset (dialog, title_attr); mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); waddstr (dialog, (char *)title); waddch (dialog, ' '); } wattrset (dialog, dialog_attr); print_autowrap (dialog, prompt, width - 2, 1, 3); print_buttons(dialog, height, width, 0); while (key != ESC) { key = wgetch (dialog); switch (key) { case 'Y': case 'y': case 'S': case 's': delwin (dialog); return 0; case 'N': case 'n': delwin (dialog); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh (dialog); break; case ' ': case '\n': delwin (dialog); return button; case ESC: break; } } delwin (dialog); return -1; /* ESC pressed */ }
void StateActionCanvas::draw(QPainter & p) { if (! visible()) return; QRect r = rect(); const BasicData * data = browser_node->get_data(); double zoom = the_canvas()->zoom(); const QPixmap * px = ProfiledStereotypes::diagramPixmap(data->get_stereotype(), the_canvas()->zoom()); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); if (px != 0) { p.setBackgroundMode(::Qt::TransparentMode); int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x(); p.drawPixmap(lft, r.y(), *px); if (fp != 0) // pixmap not really exported in SVG fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1); } else { QColor bckgrnd = p.backgroundColor(); int mw = min_width; QBrush brsh = p.brush(); QFontMetrics fm(the_canvas()->get_font(UmlNormalFont)); const char * st = data->get_short_stereotype(); const int shadow = the_canvas()->shadow(); QColor co = color(used_color); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); p.setBackgroundColor(co); p.setFont(the_canvas()->get_font(UmlNormalFont)); if (!strcmp(st, "send-signal")) { QPointArray a(6); if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } const int hh = r.height()/2; a.setPoint(0, r.left(), r.top()); a.setPoint(1, r.right() - hh, r.top()); a.setPoint(2, r.right(), r.top() + hh); a.setPoint(3, r.right() - hh, r.bottom()); a.setPoint(4, r.left(), r.bottom()); a.setPoint(5, r.left(), r.top()); if (used_color == UmlTransparent) { p.drawPolyline(a); if (fp != 0) draw_poly(fp, a, UmlTransparent); } else { if (shadow != 0) { QPointArray b(6); b.setPoint(0, r.left() + shadow, r.top() + shadow); b.setPoint(1, r.right() - hh + shadow, r.top() + shadow); b.setPoint(2, r.right() + shadow, r.top() + hh + shadow); b.setPoint(3, r.right() - hh + shadow, r.bottom() + shadow); b.setPoint(4, r.left() + shadow, r.bottom() + shadow); b.setPoint(5, r.left() + shadow, r.top() + shadow); p.setBrush(::Qt::darkGray); p.setPen(::Qt::NoPen); p.drawPolygon(b, TRUE, 0, 5); p.setPen(::Qt::SolidLine); if (fp != 0) draw_shadow(fp, b); } p.setBrush(co); p.drawPolygon(a, TRUE, 0, 5); if (fp != 0) draw_poly(fp, a, used_color); } r.setRight(r.right() - hh); mw -= hh; } else if (!strcmp(st, "receive-signal")) { QPointArray a(6); if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } const int hh = r.height()/2; a.setPoint(0, r.left(), r.top()); a.setPoint(1, r.right(), r.top()); a.setPoint(2, r.right() - hh, r.top() + hh); a.setPoint(3, r.right(), r.bottom()); a.setPoint(4, r.left(), r.bottom()); a.setPoint(5, r.left(), r.top()); if (used_color == UmlTransparent) { p.drawPolyline(a); if (fp != 0) draw_poly(fp, a, UmlTransparent); } else { if (shadow != 0) { QPointArray b(6); b.setPoint(0, r.left() + shadow, r.top() + shadow); b.setPoint(1, r.right() + shadow, r.top() + shadow); b.setPoint(2, r.right() - hh + shadow, r.top() + hh + shadow); b.setPoint(3, r.right() + shadow, r.bottom() + shadow); b.setPoint(4, r.left() + shadow, r.bottom() + shadow); b.setPoint(5, r.left() + shadow, r.top() + shadow); p.setBrush(::Qt::darkGray); p.setPen(::Qt::NoPen); p.drawPolygon(b, TRUE, 0, 5); p.setPen(::Qt::SolidLine); if (fp != 0) draw_shadow(fp, b); } p.setBrush(co); p.drawPolygon(a, TRUE, 0, 5); if (fp != 0) draw_poly(fp, a, used_color); } r.setRight(r.right() - hh); mw -= hh; } else { if (used_color != UmlTransparent) { if (shadow != 0) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1, ::Qt::darkGray); p.fillRect (r.left() + shadow, r.bottom(), r.width() - 1, shadow, ::Qt::darkGray); if (fp != 0) { fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", ::Qt::darkGray.rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1); fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", ::Qt::darkGray.rgb()&0xffffff, r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1); } } } p.setBrush(co); p.drawRect(r); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); if (st[0] != 0) { r.setTop(r.top() + fm.height() / 2); p.drawText(r, ::Qt::AlignHCenter, QString("<<") + toUnicode(st) + ">>"); if (fp != 0) draw_text(r, ::Qt::AlignHCenter, QString("<<") + toUnicode(st) + ">>", p.font(), fp); r.setTop(r.top() + 3*fm.height()/2); } } r.setLeft(r.left() + (r.width() + (int) (8 * zoom) - mw)/2 + 1); p.drawText(r, ::Qt::AlignVCenter, s); if (fp != 0) { draw_text(r, ::Qt::AlignVCenter, s, p.font(), fp); fputs("</g>\n", fp); } p.setBrush(brsh); p.setBackgroundColor(bckgrnd); } if (selected()) show_mark(p, rect()); }
/* * Display a menu for choosing among a number of options */ int dialog_menu (const char *title, const char *prompt, int height, int width, int menu_height, const char *current, int item_no, struct dialog_list_item ** items) { int i, j, x, y, box_x, box_y; int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice; WINDOW *dialog, *menu; FILE *f; max_choice = MIN (menu_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); mvwaddch (dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); wbkgdset (dialog, dialog_attr & A_COLOR); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { /* truncate long title -- mec */ char * title2 = malloc(width-2+1); memcpy( title2, title, width-2 ); title2[width-2] = '\0'; title = title2; } if (title != NULL) { wattrset (dialog, title_attr); mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); waddstr (dialog, (char *)title); waddch (dialog, ' '); } wattrset (dialog, dialog_attr); print_autowrap (dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin (dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad (menu, TRUE); /* draw a box around the menu items */ draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2, menubox_border_attr, menubox_attr); /* * Find length of longest item in order to center menu. * Set 'choice' to default item. */ item_x = 0; for (i = 0; i < item_no; i++) { item_x = MAX (item_x, MIN(menu_width, strlen (items[i]->name) + 2)); if (strcmp(current, items[i]->tag) == 0) choice = i; } item_x = (menu_width - item_x) / 2; /* get the scroll info from the temp file */ if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) { if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) && (scroll+max_choice > choice) && (scroll >= 0) && (scroll+max_choice <= item_no) ) { first_item = scroll; choice = choice - scroll; fclose(f); } else { scroll=0; remove("lxdialog.scrltmp"); fclose(f); f=NULL; } } if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) { if (choice >= item_no-max_choice/2) scroll = first_item = item_no-max_choice; else scroll = first_item = choice - max_choice/2; choice = choice - scroll; } /* Print the menu */ for (i=0; i < max_choice; i++) { print_item (menu, items[first_item + i]->name, i, i == choice, (items[first_item + i]->tag[0] != ':')); } wnoutrefresh (menu); print_arrows(dialog, item_no, scroll, box_y, box_x+item_x+1, menu_height); wbkgdset (dialog, 0); print_buttons (dialog, height, width, 0); wbkgdset (dialog, dialog_attr & A_COLOR); wmove (menu, choice, item_x+1); wrefresh (menu); while (key != ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice+1; i < max_choice; i++) { j = first_alpha(items[scroll + i]->name, "YyNnMmHh"); if (key == tolower(items[scroll + i]->name[j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { j = first_alpha(items[scroll + i]->name, "YyNnMmHh"); if (key == tolower(items[scroll + i]->name[j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { print_item (menu, items[scroll + choice]->name, choice, FALSE, (items[scroll + choice]->tag[0] != ':')); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ scrollok (menu, TRUE); wscrl (menu, -1); scrollok (menu, FALSE); scroll--; print_item (menu, items[scroll]->name, 0, FALSE, (items[scroll]->tag[0] != ':')); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item (menu, items[scroll + choice]->name, choice, FALSE, (items[scroll + choice]->tag[0] != ':')); if ((choice > max_choice-3) && (scroll + max_choice < item_no) ) { /* Scroll menu up */ scrollok (menu, TRUE); scroll (menu); scrollok (menu, FALSE); scroll++; print_item (menu, items[scroll + max_choice - 1]->name, max_choice-1, FALSE, (items[scroll + max_choice - 1]->tag[0] != ':')); } else choice = MIN(choice+1, max_choice-1); } else if (key == KEY_PPAGE) { scrollok (menu, TRUE); for (i=0; (i < max_choice); i++) { if (scroll > 0) { wscrl (menu, -1); scroll--; print_item (menu, items[scroll]->name, 0, FALSE, (items[scroll]->tag[0] != ':')); } else { if (choice > 0) choice--; } } scrollok (menu, FALSE); } else if (key == KEY_NPAGE) { for (i=0; (i < max_choice); i++) { if (scroll+max_choice < item_no) { scrollok (menu, TRUE); scroll(menu); scrollok (menu, FALSE); scroll++; print_item (menu, items[scroll + max_choice - 1]->name, max_choice-1, FALSE, (items[scroll + max_choice - 1]->tag[0] != ':')); } else { if (choice+1 < max_choice) choice++; } } } else choice = i; print_item (menu, items[scroll + choice]->name, choice, TRUE, (items[scroll + choice]->tag[0] != ':')); print_arrows(dialog, item_no, scroll, box_y, box_x+item_x+1, menu_height); wnoutrefresh (dialog); wrefresh (menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); wbkgdset (dialog, 0); print_buttons(dialog, height, width, button); wbkgdset (dialog, dialog_attr & A_COLOR); wrefresh (menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': /* save scroll info */ if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { fprintf(f,"%d\n",scroll); fclose(f); } delwin (dialog); items[scroll + choice]->selected = 1; switch (key) { case 's': return 3; case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; } return 0; case 'h': case '?': button = 2; case '\n': delwin (dialog); items[scroll + choice]->selected = 1; remove("lxdialog.scrltmp"); return button; case 'e': case 'x': key = ESC; case ESC: break; } } delwin (dialog); remove("lxdialog.scrltmp"); return -1; /* ESC pressed */ }
/* * Display text from a file in a dialog box. */ int dialog_textbox (const char *title, const char *file, int height, int width) { int i, x, y, cur_x, cur_y, fpos, key = 0; int passed_end; char search_term[MAX_LEN + 1]; WINDOW *dialog, *text; search_term[0] = '\0'; /* no search term entered yet */ /* Open input file for reading */ if ((fd = open (file, O_RDONLY)) == -1) { endwin (); fprintf (stderr, "\nCan't open input file in dialog_textbox().\n"); exit (-1); } /* Get file size. Actually, 'file_size' is the real file size - 1, since it's only the last byte offset from the beginning */ if ((file_size = lseek (fd, 0, SEEK_END)) == -1) { endwin (); fprintf (stderr, "\nError getting file size in dialog_textbox().\n"); exit (-1); } /* Restore file pointer to beginning of file after getting file size */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } /* Allocate space for read buffer */ if ((buf = malloc (BUF_SIZE + 1)) == NULL) { endwin (); fprintf (stderr, "\nCan't allocate memory in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; /* mark end of valid data */ page = buf; /* page is pointer to start of page to be displayed */ /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); /* Create window for text region, used for scrolling text */ text = subwin (dialog, height - 4, width - 2, y + 1, x + 1); wattrset (text, dialog_attr); wbkgdset (text, dialog_attr & A_COLOR); keypad (text, TRUE); /* register the new window, along with its borders */ draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); mvwaddch (dialog, height-3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); wbkgdset (dialog, dialog_attr & A_COLOR); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { /* truncate long title -- mec */ char * title2 = malloc(width-2+1); memcpy( title2, title, width-2 ); title2[width-2] = '\0'; title = title2; } if (title != NULL) { wattrset (dialog, title_attr); mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); waddstr (dialog, (char *)title); waddch (dialog, ' '); } print_button (dialog, " Exit ", height - 2, width / 2 - 4, TRUE); wnoutrefresh (dialog); getyx (dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear (text, height - 4, width - 2, dialog_attr); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); while ((key != ESC) && (key != '\n')) { key = wgetch (dialog); switch (key) { case 'E': /* Exit */ case 'e': case 'X': case 'x': delwin (dialog); free (buf); close (fd); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; /* First page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos > bytes_read) { /* Yes, we have to read it in */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in " "dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'G': /* Last page */ case KEY_END: end_reached = 1; /* Last page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos < file_size) { /* Yes, we have to read it in */ if (lseek (fd, -BUF_SIZE, SEEK_END) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf + bytes_read; back_lines (height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines (page_length + 1); /* We don't call print_page() here but use scrolling to ensure faster screen update. However, 'end_reached' and 'page_length' should still be updated, and 'page' should point to start of next page. This is done by calling get_line() in the following 'for' loop. */ scrollok (text, TRUE); wscrl (text, -1); /* Scroll text region down one line */ scrollok (text, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < height - 4; i++) { if (!i) { /* print first line of page */ print_line (text, 0, width - 2); wnoutrefresh (text); } else /* Called to update 'end_reached' and 'page' */ get_line (); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines (page_length + height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok (text, TRUE); scroll (text); /* Scroll text region up one line */ scrollok (text, FALSE); print_line (text, height - 5, width - 2); wnoutrefresh (text); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case KEY_NPAGE: /* Next page */ case ' ': if (end_reached) break; begin_reached = 0; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll <= 0) break; if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines (page_length); print_page (text, height - 4, width - 2); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll >= MAX_LEN) break; hscroll++; /* Reprint current page to scroll horizontally */ back_lines (page_length); print_page (text, height - 4, width - 2); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case ESC: break; } } delwin (dialog); free (buf); close (fd); return 1; /* ESC pressed */ }
int ifs_cfg(char *title, char *prompt, int height, int width, int y, int x, char *dev) { WINDOW *w; int i, n, k, j; char titlez[80]; char devz[80]; int foo, done, key, set; struct device d; int ret = -1; int dev_id; init_dialog(); dialog_clear(); draw_shadow(stdscr, y, x, height, width); w = newwin(height, width, y, x); draw_box(w, 0, 0, height, width, dialog_attr, border_attr); wattrset(w, border_attr); keypad(w, TRUE); /* draw pretty lines outside. */ /* box(w, ACS_VLINE, ACS_HLINE); */ wrefresh(w); snprintf(titlez, sizeof(titlez), " [ %s ] ", title); foo = ((width / 2) - strlen(title)); wmove(w, 0, foo); wattrset(w, title_attr); waddstr(w, titlez); wattrset(w, border_attr); for (i = 1; i < (height - 1); i++) { for (n = 1; n < (width - 1); n++) { wmove(w, i, n); waddch(w, ' '); } } draw_box(w, 2, 3, 12, 44, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 4, 4); waddstr(w, " IP ->"); draw_box(w, 3, 18, 3, 25, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 7, 4); waddstr(w, " Netmask ->"); draw_box(w, 6, 18, 3, 25, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 10, 4); waddstr(w, " Gateway ->"); draw_box(w, 9, 18, 3, 25, dialog_attr, border_attr); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); d.dhcp = DHCP_DISABLED; if ((ret = device_exist(dev)) >= 0) { wattrset(w, dialog_attr); wrefresh(w); /* fill in the previously configured values */ snprintf(d.ip, sizeof(d.ip), "%s", dev_ip(dev)); if (strlen(d.ip) > 6) mvwprintw(w, 4, 19, "%s", d.ip); else bzero(d.ip, sizeof(d.ip)); snprintf(d.netmask, sizeof(d.netmask), "%s", dev_netmask(dev)); if (strlen(d.netmask) > 6) mvwprintw(w, 7, 19, "%s", d.netmask); else bzero(d.netmask, sizeof(d.netmask)); snprintf(d.gateway, sizeof(d.gateway), "%s", dev_gateway(dev)); if (strlen(d.gateway) > 6) mvwprintw(w, 10, 19, "%s", d.gateway); else bzero(d.gateway, sizeof(d.gateway)); snprintf(devz, sizeof(devz), "Editing device %s", dev); wmove(w, 1, (width / 2) - (strlen(devz) / 2)); wattrset(w, dialog_attr); waddstr(w, devz); wrefresh(w); } else { bzero(d.ip, sizeof(d.ip)); bzero(d.netmask, sizeof(d.netmask)); bzero(d.gateway, sizeof(d.gateway)); snprintf(devz, sizeof(devz), "Configuring device %s", dev); wmove(w, 1, (width / 2) - (strlen(devz) / 2)); wattrset(w, dialog_attr); waddstr(w, devz); } /* start off in first window. */ done = key = set = 0; j = 1; while (!done) { wrefresh(w); switch (j) { case 1: wattrset(w, inputbox_attr); wrefresh(w); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); if (strlen(d.ip) < 1) bzero(d.ip, sizeof(d.ip)); k = line_edit(w, 4, 19, 23, 23, inputbox_attr, 1, d.ip, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j = 1; break; } else if (k == 10) { j++; break; } break; case 2: wattrset(w, inputbox_attr); wrefresh(w); /* * print_button(w, " OK * ",height-2,(width/2)-11,FALSE); */ if (strlen(d.netmask) < 1) bzero(d.netmask, sizeof(d.netmask)); k = line_edit(w, 7, 19, 23, 23, inputbox_attr, 1, d.netmask, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 10) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j = 1; break; } break; case 3: wattrset(w, inputbox_attr); wrefresh(w); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); if (strlen(d.gateway) < 1) bzero(d.gateway, sizeof(d.gateway)); k = line_edit(w, 10, 19, 23, 23, inputbox_attr, 1, d.gateway, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 10) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j--; break; } break; case 4: wattrset(w, title_attr); wrefresh(w); curs_set(0); print_button(w, " OK ", height - 2, (width / 2) - 11, TRUE); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); wrefresh(w); key = wgetch(w); if (key == KEY_UP) { j--; break; } else if (key == 9) { j++; break; } else if (key == KEY_DOWN) { j++; break; } else if (key == 10) { done = 1; set = 1; break; } break; case 5: wattrset(w, title_attr); wrefresh(w); curs_set(0); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); print_button(w, "Cancel", height - 2, (width / 2) + 3, TRUE); wrefresh(w); key = wgetch(w); if (key == KEY_UP) { j = 4; break; } else if (key == KEY_DOWN) { j = 4; break; } else if (key == 9) { j = 1; break; } else if (key == 10) { dialog_clear(); return -1; break; } break; } } if (strlen(d.gateway) > 1) { ret = dialog_yesno("ClosedBSD", "Would you like this device to be the default gateway?", -1, -1); if (ret == 0) { if ((ext_exist()) == -1) { d.ext = 1; } else { dialog_clear(); ret = dialog_yesno("ClosedBSD", "You already have a default gateway set. Overwrite?", -1, -1); if (ret == 0) { unset_ext(d.id); } else { d.ext = 0; } } } else { d.ext = 0; } } else d.ext = 0; strcpy(d.device, dev); if (set == 1) { dialog_clear(); dev_id = device_exist(d.device); switch (dev_id) { case -1: d.id = next_device_id(); insert_device(d); break; default: ret = dialog_yesno("ClosedBSD", "This device is already configured. Overwrite?", -1, -1); if (ret == 0) { d.id = dev_id; insert_device(d); break; } else { break; } } } dialog_clear(); wrefresh(w); end_dialog(); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
void drawscene(void){ //draw the whole scene GLint viewport[4]; glGetIntegerv( GL_VIEWPORT, viewport ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 45, double(viewport[2])/viewport[3], 0.1, 1000 ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( 100,25,200,0,0,lookz, 0,1,0 ); //the PRP is at (100,25,200), looking at (0,0,lookz), VUP is (0,1,0) glMultMatrixf( gsrc_getmo() ); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //initialize the display mode, double buffer glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); //enable depth test glClear(GL_COLOR_BUFFER_BIT); //Add a ambient light GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //the ambient Color is (0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add directed light GLfloat lightColor1[] = {0.3f, 0.3f, 0.3f, 1.0f}; //Color (0.5, 0.2, 0.2) GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; //the light comes from the direction (-1, 0.5, 0.5) glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); //Add a point light source GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5) GLfloat lightPos0[] = {-20.0f, 50.0f, 70.0f, 1.0f}; //Positioned at (-20,50,70) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); ////////draw the cube used for the background///////////////////////////////////////// glPushMatrix ( ); glTranslatef(100,150,100); CreateBox(); glPopMatrix ( ); ////////////////////////////////////////////////////////////////// glPushMatrix(); glTranslatef(-20.0f,50.0f,70.0f); draw_sun(); //draw a sun positioned at the point light source glPopMatrix (); GLfloat M[16]= { 1, 0, 0, 0, 0, 1, 0, -1/(50-0.1), 0, 0, 1, 0, 0, 0, 0, 0 }; //perspective projection draw_object(); //draw the whole object /////////////////draw the shadow/////////////////////////// //glPushMatrix(); glMatrixMode(GL_MODELVIEW); glTranslatef(-20,50,70); //M wc<-s glMultMatrixf(M); //perspective project glTranslatef(20,-50,-70); //M s<-wc glColor4f(0.3f,0.3f,0.3f,0.2f); //the color of the shadow draw_shadow(); //draw the shadows glutSwapBuffers(); //swap buffers to display glFlush(); }