bool top_globalstats_resize(void *ptr, int width, int height, int *consumed_height) { struct globalstat_controller *c = ptr; int i; top_log("%s\n", __func__); *consumed_height = 0; setup_globalstats_geometry(c, width, height, consumed_height); if(ERR == wresize(c->window, *consumed_height, width)) { top_log("wresize error: height %d width %d\n", *consumed_height, width); return true; } if(ERR == move_panel(c->panel, 0, 0)) { top_log("move_panel error: 0 0\n"); return true; } for(i = 0; i < GLOBALSTAT_TOTAL; ++i) { struct globalstat *gs = c->stats + i; // MWW: Skip the frameworks window if we've got them disabled if (!top_prefs_get_frameworks() && (i == GLOBALSTAT_SHAREDLIBS)) continue; if(skip_globalstat(i)) { /* Skip and hide the panels for these. */ hide_panel(gs->panel); continue; } gs = c->stats + i; /* * Avoid errors below by resizing and moving the panel to a known * good size/offfset. */ wresize(gs->window, 1, 1); move_panel(gs->panel, 0, 0); if(ERR == move_panel(gs->panel, gs->y, gs->x)) return true; if(ERR == wresize(gs->window, gs->size.height, gs->size.width)) return true; if(ERR == werase(gs->window)) return true; } return false; }
static void bw_show_value (float val, bw_show_t *bw, int idx) { float w; int pos; float delta; float minval,maxval; WINDOW *bw_bar_w = panel_window (bw->bar_p[idx]); WINDOW *bw_cell_w = panel_window (bw->cell_p[idx]); PANEL *bw_slider_p = bw->slider_p[idx]; minval = 0.01; maxval = 5.00; delta = maxval - minval; w = getmaxx (bw_bar_w) - 1; pos = (w/delta) * val; if (val >= minval && val <=maxval) { move_panel (bw_slider_p,getbegy (panel_window (bw_slider_p)),getbegx (bw_bar_w) + pos ); } mvwprintw (bw_cell_w,0,0,"%f",val); update_panels (); doupdate (); return; }
static int lcp_move_panel(lua_State *L) { PANEL *p = lcp_check(L, 1); int starty = luaL_checkint(L, 2); int startx = luaL_checkint(L, 3); lua_pushboolean(L, B(move_panel(p, starty, startx))); return 1; }
/* window:move(x, y) move the window */ int lui_move_window(lua_State *L) { PANEL *p = check_window(L, 1); const int x = luaL_checkint(L, 2); const int y = luaL_checkint(L, 3); move_panel(p, y, x); return 0; }
void CWidget::update(int c) { if(_visible) { move_panel(_panel, _pos.y(), _pos.x()); //top_panel(_panel); if(_layout) _layout->update(c); } }
void heartbeat(void) { time_t now = time(NULL); struct tm *ptm = localtime(&now); static int x = 0, y = 0, dx = 1, dy = 1; static NEWWIN *hb_win = NULL; x += dx; y += dy; if (x >= (max_x - 8)) { dx = -(myrand(1) + 1); x = max_x - (8 + 1); } else if (x < 0) { dx = (myrand(2) + 1); x = 0; } if (y >= max_y) { dy = -(myrand(2) + 1); y = max_y - 1; } else if (y < 0) { dy = (myrand(2) + 1); y = 0; } if (dx == 0 && dy == 0) { dy = 1; dy = -1; } if (!hb_win) { hb_win = create_popup(1, 8); } move_panel(hb_win -> pwin, y, x); ui_inverse_on(hb_win); mvwprintw(hb_win -> win, 0, 0, "%02d:%02d:%02d", ptm -> tm_hour, ptm -> tm_min, ptm -> tm_sec); ui_inverse_off(hb_win); mydoupdate(); }
void CSeparatorWidget::update(int c) { if(_visible && _changed) { move_panel(_panel, _pos.y(), _pos.x()); top_panel(_panel); wclear(_window); uint tw = _size.width() - _leftMargin - _rightMargin; mvwhline(_window, _topMargin, _leftMargin, 0, tw); _changed = false; } }
static void my_move_panel(PANEL ** pans, int which, bool continuous) { if (pans[which] != 0) { int code; int y0, x0; int y1, x1; WINDOW *win = panel_window(pans[which]); char also[80]; getbegyx(win, y0, x0); sprintf(also, " (start %d,%d)", y0, x0); wmove(stdscr, y0, x0); while ((code = get_position("Move panel", also, which, &x1, &y1)) == 0) { if (continuous) { move_panel(pans[which], y1, x1); pflush(); } } if (code > 0) { move_panel(pans[which], y1, x1); } } }
void CLabel::update(int c) { if(_visible && _changed) { move_panel(_panel, _pos.y(), _pos.x()); top_panel(_panel); wclear(_window); uint tw = _size.width() - _leftMargin - _rightMargin; if(_centered) mvwaddnstr(_window, _topMargin, _leftMargin + (_text.size() < tw ? ( tw - _text.size() ) / 2 : 0), _text.c_str(), tw); else mvwaddnstr(_window, _topMargin, _leftMargin, _text.c_str(), tw); _changed = false; } }
int main() { WINDOW *my_wins[3]; PANEL *my_panels[3]; PANEL_DATA *top; PANEL *stack_top; WINDOW *temp_win, *old_win; int ch; int newx, newy, neww, newh; int size = FALSE, move = FALSE; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); /* Initialize all the colors */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_CYAN, COLOR_BLACK); init_wins(my_wins, 3); /* Attach a panel to each window */ /* Order is bottom up */ my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ set_user_ptrs(my_panels, 3); /* Update the stacking order. 2nd panel will be on top */ update_panels(); /* Show it on the screen */ attron(COLOR_PAIR(4)); mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); attroff(COLOR_PAIR(4)); doupdate(); stack_top = my_panels[2]; top = (PANEL_DATA *)panel_userptr(stack_top); newx = top->x; newy = top->y; neww = top->w; newh = top->h; while((ch = getch()) != KEY_F(1)) { switch(ch) { case 9: /* Tab */ top = (PANEL_DATA *)panel_userptr(stack_top); top_panel(top->next); stack_top = top->next; top = (PANEL_DATA *)panel_userptr(stack_top); newx = top->x; newy = top->y; neww = top->w; newh = top->h; break; case 'r': /* Re-Size*/ size = TRUE; attron(COLOR_PAIR(4)); mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press <ENTER> to end resizing"); refresh(); attroff(COLOR_PAIR(4)); break; case 'm': /* Move */ attron(COLOR_PAIR(4)); mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press <ENTER> to end moving"); refresh(); attroff(COLOR_PAIR(4)); move = TRUE; break; case KEY_LEFT: if(size == TRUE) { --newx; ++neww; } if(move == TRUE) --newx; break; case KEY_RIGHT: if(size == TRUE) { ++newx; --neww; } if(move == TRUE) ++newx; break; case KEY_UP: if(size == TRUE) { --newy; ++newh; } if(move == TRUE) --newy; break; case KEY_DOWN: if(size == TRUE) { ++newy; --newh; } if(move == TRUE) ++newy; break; case 10: /* Enter */ move(LINES - 4, 0); clrtoeol(); refresh(); if(size == TRUE) { old_win = panel_window(stack_top); temp_win = newwin(newh, neww, newy, newx); replace_panel(stack_top, temp_win); win_show(temp_win, top->label, top->label_color); delwin(old_win); size = FALSE; } if(move == TRUE) { move_panel(stack_top, newy, newx); move = FALSE; } break; } attron(COLOR_PAIR(4)); mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); attroff(COLOR_PAIR(4)); refresh(); update_panels(); doupdate(); } endwin(); return 0; }
void CListWidget::update(int c) { if(_visible) { uint tw = _size.width(); uint th = _size.height(); if(focused()) { #ifdef __PDCURSES__ // Mouse wheel scrolling if(c == KEY_MOUSE && _count > th) { if(Mouse_status.changes == MOUSE_WHEEL_DOWN) { _scroll += 4; _changed = true; } else if(Mouse_status.changes == MOUSE_WHEEL_UP && _scroll >= 4) { _scroll -= 4; _changed = true; } } #endif } if((_listenKeys || focused()) && _count > th) { if(c == KEY_NPAGE) // PAGE DOWN { _scroll += 4; _changed = true; } else if(c == KEY_PPAGE && _scroll >= 4) // PAGE UP { _scroll -= 4; _changed = true; } } if(_changed) { move_panel(_panel, _pos.y(), _pos.x()); top_panel(_panel); wclear(_window); if((_count < th && _scroll < _count) || (_count > th && _scroll > _count)) _scroll = _count; if(_count > th && _scroll < th) _scroll = th; uint b = 0, n = 0; for(uint i = 0; i < _items.size() && i < _scroll + b; ++i) { if(_items[i]->nocrlf()) b++; if(!_items[i]->nocrlf()) n = 0; const string &message = _items[i]->text(); for(uint j = 0; j < _leftMargin; ++j) waddch(_window, ' '); attr_t a = attribute(_items[i]->backgroundColor(), _items[i]->foregroundColor(), _items[i]->bold()); wattr_on(_window, a, 0); n++; for(uint j = 0; j < message.size(); ++j, n++) { if(n >= tw - _leftMargin - _rightMargin) { n = 0; wattr_off(_window, a, 0); waddch(_window, '\n'); for(uint j = 0; j < _leftMargin; ++j) waddch(_window, ' '); wattr_on(_window, a, 0); } waddch(_window, toULong(message[j])); } wattr_off(_window, a, 0); if(i < _scroll + b - 1 && i != _items.size() - 1 && !_items[i]->nocrlf()) waddch(_window, '\n'); } _changed = false; } } }
void CTextEdit::update(int c) { if(_visible) { bool alwaysFocused = false; #ifdef NO_MOUSE alwaysfocused = true; // If we have no mouse, we can't focus widgets so let's have it always focused. #endif if((_requireFocused ? focused() : true) && (_parent ? _parent->focused() || alwaysFocused : true)) { switch(c) { case ERR: break; #ifdef __PDCURSES__ case 3: // copy { string clipboard = UTIL_Latin1ToUTF8(_text); PDC_setclipboard(clipboard.c_str(), clipboard.length()); break; } case 22: // paste { char *clipboard = NULL; long length = 0; if(PDC_getclipboard(&clipboard, &length) == PDC_CLIP_SUCCESS) { _text += string(clipboard, length); PDC_freeclipboard(clipboard); } break; } #endif case KEY_UP: if(!_history.empty()) { if(_selectedHistory > 0) _text = _history[--_selectedHistory]; else if(_selectedHistory == 0) _text = _history[0]; } break; case KEY_DOWN: if(!_history.empty()) { if(_selectedHistory < _history.size() - 1) _text = _history[++_selectedHistory]; else if(_selectedHistory == _history.size() - 1) _text = _history[_history.size() - 1]; } break; case 8: case 127: case KEY_BACKSPACE: case KEY_DC: if(!_text.empty()) _text.erase(_text.end() - 1); break; case 27: _text.clear(); break; case 10: case 13: #ifdef WIN32 case PADENTER: #endif if(!_text.empty()) { _history.push_back(_text); _selectedHistory = _history.size(); forward( new CFwdData(_fwdTypeEnter, _text, 0 )); _text.clear(); } break; #ifdef WIN32 case PADSLASH: _text += '/'; break; case PADSTAR: _text += '*'; break; case PADMINUS: _text += '-'; break; case PADPLUS: _text += '+'; break; #endif default: if(c >= 32 && c <= 255) _text += c; break; } } if(c != ERR) { move_panel(_panel, _pos.y(), _pos.x()); top_panel(_panel); wclear(_window); string temp = UTIL_Latin1ToUTF8(_text); // print text mvwaddstr(_window, 0, 0, temp.c_str()); } } }
void CTabWidget::update(int c) { if(_visible) { move_panel(_panel, _pos.y(), _pos.x()); //top_panel(_panel); wclear(_window); if(_listenKeys) { if(c == KEY_LEFT) { if(currentIndex() - 1 >= 0) setCurrentIndex(currentIndex() - 1); else setCurrentIndex(count() - 1); } else if(c == KEY_RIGHT) { if(currentIndex() + 1 < int(count())) setCurrentIndex(currentIndex() + 1); else setCurrentIndex(0); } } uint tw = _size.width() - _leftMargin - _rightMargin; // Is left mouse button pressed? #ifdef __PDCURSES__ bool leftClick = focused() && Mouse_status.button[0] == BUTTON_PRESSED; #else bool leftClick = false; MEVENT event; if(getmouse(&event) == OK) leftClick = focused() && (event.bstate & BUTTON1_PRESSED); #endif int k = 0; for(uint i = 0; i < _widgets.size(); ++i) { if(leftClick) { if(_mousePos.x() >= _pos.x() + _leftMargin + k && _mousePos.x() < _pos.x() + _leftMargin + k + _widgets[i]->name().size() && _mousePos.y() == (_bottom ? _pos.y() + _size.height() - 1 : _pos.y())) { // select tab setCurrentIndex(i); } } if(currentIndex() == i) wattr_on(_window, A_BOLD, 0); mvwaddstr(_window, _bottom ? _size.height() - 1 : 0, _leftMargin + k, _widgets[i]->name().c_str()); if(_currentIndex == i) wattr_off(_window, A_BOLD, 0); k += _widgets[i]->name().size() + 1; } if(_layout) { if(_changed) { DEBUG_ui("CTabWidget::update, 0"); _layout->setSize(_size.width(), _size.height() - 1); _layout->setPosition(_pos.x(), _bottom ? _pos.y() : _pos.y() + 1); _changed = false; DEBUG_ui("CTabWidget::update, 1"); } _layout->update(c); } } }
void move(short x, short y) { move_panel(pan, y, x); };
int main(int argc, char **argv) { int itmp, y; if (argc > 1 && atol(argv[1])) nap_msec = atol(argv[1]); #ifdef XCURSES Xinitscr(argc, argv); #else initscr(); #endif backfill(); for (y = 0; y < 5; y++) { p1 = mkpanel(10, 10, 0, 0); set_panel_userptr(p1, "p1"); p2 = mkpanel(14, 14, 5, 5); set_panel_userptr(p2, "p2"); p3 = mkpanel(6, 8, 12, 12); set_panel_userptr(p3, "p3"); p4 = mkpanel(10, 10, 10, 30); w4 = panel_window(p4); set_panel_userptr(p4, "p4"); p5 = mkpanel(10, 10, 13, 37); w5 = panel_window(p5); set_panel_userptr(p5, "p5"); fill_panel(p1); fill_panel(p2); fill_panel(p3); fill_panel(p4); fill_panel(p5); hide_panel(p4); hide_panel(p5); pflush(); wait_a_while(nap_msec); saywhat("h3 s1 s2 s4 s5;"); move_panel(p1, 0, 0); hide_panel(p3); show_panel(p1); show_panel(p2); show_panel(p4); show_panel(p5); pflush(); wait_a_while(nap_msec); saywhat("s1;"); show_panel(p1); pflush(); wait_a_while(nap_msec); saywhat("s2;"); show_panel(p2); pflush(); wait_a_while(nap_msec); saywhat("m2;"); move_panel(p2, 10, 10); pflush(); wait_a_while(nap_msec); saywhat("s3;"); show_panel(p3); pflush(); wait_a_while(nap_msec); saywhat("m3;"); move_panel(p3, 5, 5); pflush(); wait_a_while(nap_msec); saywhat("b3;"); bottom_panel(p3); pflush(); wait_a_while(nap_msec); saywhat("s4;"); show_panel(p4); pflush(); wait_a_while(nap_msec); saywhat("s5;"); show_panel(p5); pflush(); wait_a_while(nap_msec); saywhat("t3;"); top_panel(p3); pflush(); wait_a_while(nap_msec); saywhat("t1;"); top_panel(p1); pflush(); wait_a_while(nap_msec); saywhat("t2;"); top_panel(p2); pflush(); wait_a_while(nap_msec); saywhat("t3;"); top_panel(p3); pflush(); wait_a_while(nap_msec); saywhat("t4;"); top_panel(p4); pflush(); wait_a_while(nap_msec); for (itmp = 0; itmp < 6; itmp++) { saywhat("m4;"); mvwaddstr(w4, 3, 1, mod[itmp]); move_panel(p4, 4, itmp * 10); mvwaddstr(w5, 4, 1, mod[itmp]); pflush(); wait_a_while(nap_msec); saywhat("m5;"); mvwaddstr(w4, 4, 1, mod[itmp]); move_panel(p5, 7, itmp * 10 + 6); mvwaddstr(w5, 3, 1, mod[itmp]); pflush(); wait_a_while(nap_msec); } saywhat("m4;"); move_panel(p4, 4, itmp * 10); pflush(); wait_a_while(nap_msec); saywhat("t5;"); top_panel(p5); pflush(); wait_a_while(nap_msec); saywhat("t2;"); top_panel(p2); pflush(); wait_a_while(nap_msec); saywhat("t1;"); top_panel(p1); pflush(); wait_a_while(nap_msec); saywhat("d2;"); rmpanel(p2); pflush(); wait_a_while(nap_msec); saywhat("h3;"); hide_panel(p3); pflush(); wait_a_while(nap_msec); saywhat("d1;"); rmpanel(p1); pflush(); wait_a_while(nap_msec); saywhat("d4; "); rmpanel(p4); pflush(); wait_a_while(nap_msec); saywhat("d5; "); rmpanel(p5); pflush(); wait_a_while(nap_msec); if (nap_msec == 1) break; nap_msec = 100L; } endwin(); return 0; } /* end of main */
static void db_show_value (float val, db_show_t *db , int idx) { float h; int pos,minpos,maxpos; float delta; float dist; float minval,maxval; PANEL *sliderp = db->slider_p[idx]; WINDOW *bar_win = panel_window (db->bar_p[idx]); WINDOW *sliderw = panel_window (sliderp); minval = -12.00; maxval = 24.00; minpos = 2; maxpos = getmaxy (bar_win) - 1; h = getmaxy (bar_win) - 1; if (val <= minval) { pos = minpos; } else if (val >= maxval) { pos = maxpos; } else { dist = fabsf (val - minval); delta = fabsf (maxval - minval); pos = floor ((h/delta) * dist); } if (pos <= minpos) { pos = minpos; } if (pos >= maxpos) { pos = maxpos; } wattron (sliderw,COLOR_PAIR (8)); if (val>=0) { mvwprintw (sliderw,0,0,"+"); } else { mvwprintw (sliderw,0,0,"-"); } mvwprintw (sliderw,0,1,"%4.1fdB",fabsf(val)); wattroff (sliderw,COLOR_PAIR (8)); move_panel (sliderp,getbegy (bar_win) + getmaxy (bar_win) - pos,getbegx (sliderw)); update_panels (); doupdate (); return; }
static void demo_panels(void (*myInit) (void), void (*myFill) (PANEL *)) { int itmp; PANEL *px[MAX_PANELS + 1]; scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */ refresh(); myInit(); for (itmp = 1; itmp <= MAX_PANELS; ++itmp) px[itmp] = 0; px[1] = mkpanel(COLOR_RED, LINES / 2 - 2, COLS / 8 + 1, 0, 0); px[2] = mkpanel(COLOR_GREEN, LINES / 2 + 1, COLS / 7, LINES / 4, COLS / 10); px[3] = mkpanel(COLOR_YELLOW, LINES / 4, COLS / 10, LINES / 2, COLS / 9); px[4] = mkpanel(COLOR_BLUE, LINES / 2 - 2, COLS / 8, LINES / 2 - 2, COLS / 3); px[5] = mkpanel(COLOR_MAGENTA, LINES / 2 - 2, COLS / 8, LINES / 2, COLS / 2 - 2); myFill(px[1]); myFill(px[2]); myFill(px[3]); myFill(px[4]); myFill(px[5]); hide_panel(px[4]); hide_panel(px[5]); pflush(); saywhat(""); wgetch(stdscr); saywhat("h3 s1 s2 s4 s5"); move_panel(px[1], 0, 0); hide_panel(px[3]); show_panel(px[1]); show_panel(px[2]); show_panel(px[4]); show_panel(px[5]); pflush(); wgetch(stdscr); canned_panel(px, "s1"); canned_panel(px, "s2"); saywhat("m2"); move_panel(px[2], LINES / 3 + 1, COLS / 8); pflush(); wgetch(stdscr); canned_panel(px, "s3"); saywhat("m3"); move_panel(px[3], LINES / 4 + 1, COLS / 15); pflush(); wgetch(stdscr); canned_panel(px, "b3"); canned_panel(px, "s4"); canned_panel(px, "s5"); canned_panel(px, "t3"); canned_panel(px, "t1"); canned_panel(px, "t2"); canned_panel(px, "t3"); canned_panel(px, "t4"); for (itmp = 0; itmp < 6; itmp++) { WINDOW *w4 = panel_window(px[4]); WINDOW *w5 = panel_window(px[5]); saywhat("m4"); wmove(w4, LINES / 8, 1); waddstr(w4, mod[itmp]); move_panel(px[4], LINES / 6, itmp * (COLS / 8)); wmove(w5, LINES / 6, 1); waddstr(w5, mod[itmp]); pflush(); wgetch(stdscr); saywhat("m5"); wmove(w4, LINES / 6, 1); waddstr(w4, mod[itmp]); move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6); wmove(w5, LINES / 8, 1); waddstr(w5, mod[itmp]); pflush(); wgetch(stdscr); } saywhat("m4"); move_panel(px[4], LINES / 6, itmp * (COLS / 8)); pflush(); wgetch(stdscr); canned_panel(px, "t5"); canned_panel(px, "t2"); canned_panel(px, "t1"); canned_panel(px, "d2"); canned_panel(px, "h3"); canned_panel(px, "d1"); canned_panel(px, "d4"); canned_panel(px, "d5"); canned_panel(px, "d3"); wgetch(stdscr); erase(); endwin(); }
static VALUE rbncurs_c_move_panel(VALUE rb_panel, VALUE starty, VALUE startx) { return INT2NUM(move_panel(get_panel(rb_panel), NUM2INT(starty), NUM2INT(startx))); }
/** * Move window around terminal */ void moveWindow(struct panelw *p, int x, int y) { move_panel(p->panel, y, x); refresh(); }
/*#DOC*/ int view_move(View v, int x, int y) { x = viewP_posrelat(x, TERM_W); y = viewP_posrelat(y, TERM_H); return move_panel(view_pan(v), y, x); }