예제 #1
0
void create_map(MAP *p_map, bool flag)
{	int i, j;
	int x, y, w, h;

	x = p_map->startx;
	y = p_map->starty;
	w = p_map->width;
	h = p_map->height;

	if(flag == TRUE)
	{	mvaddch(y, x, p_map->border.tl); // augša kreisā
		mvaddch(y, x + w, p_map->border.tr); // augša labā
		mvaddch(y + h, x, p_map->border.bl); // kreisā apakša
		mvaddch(y + h, x + w, p_map->border.br); // labā apakša
		mvhline(y, x + 1, p_map->border.ts, w - 1); // augša
		mvhline(y + h, x + 1, p_map->border.bs, w - 1); // apakša
		mvvline(y + 1, x, p_map->border.ls, h - 1); // kreisā puse
		mvvline(y + 1, x + w, p_map->border.rs, h - 1); // labā puse

	}
	else
		for(j = y; j <= y + h; ++j)
			for(i = x; i <= x + w; ++i)
				mvaddch(j, i, ' ');
				
	refresh();

}
예제 #2
0
void create_tank_down(TANK *p_tank, bool flag)
{	int i, j;
	int x, y, w, h;

	x = p_tank->startx;
	y = p_tank->starty;
	w = p_tank->width;
	h = p_tank->height;

	if(flag == TRUE)
	{	mvaddch(y, x, p_tank->border.tl); // augša kreisā
		mvaddch(y, x + w, p_tank->border.tr); // augša labā
		mvaddch(y + h, x, p_tank->border.bl); // kreisā apakša
		mvaddch(y + h, x + w, p_tank->border.br); // labā apakša
		mvhline(y, x + 1, p_tank->border.ts, w - 1); // augša
		mvhline(y + h, x + 1, p_tank->border.bs, w - 1); // apakša
		mvvline(y + 1, x, p_tank->border.ls, h - 1); // kreisā puse
		mvvline(y + 1, x + w, p_tank->border.rs, h - 1); // labā puse

		mvaddch(y+h, x + w/2, p_tank->border.gt); //stobra gals
		mvaddch(y+h-1, x + w/2, p_tank->border.gm); // stobra vidus
		mvaddch(y+2, x + w/2, p_tank->border.gb); // stobra apakša
	}
	else
		for(j = y; j <= y + h; ++j)
			for(i = x; i <= x + w; ++i)
				mvaddch(j, i, ' ');
				
	refresh();

}
예제 #3
0
void create_box( WIN *p_win ) {
  int x = p_win->startx, 
      y = p_win->starty, 
      w = p_win->width, 
      h = p_win->height;

  WIN_BORDER b = p_win->border;

  // Draw the 4 corners
  mvaddch( y, x, b.tl );
  mvaddch( y, (x + w), b.tr );
  mvaddch( (y + h), x, b.bl );
  mvaddch( (y + h), (x + w), b.br );

  // Draw the top side and bottom side
  mvhline( y, (x + 1), b.ts, (w - 1) );
  mvhline( (y + h), (x + 1), b.bs, (w - 1) );

  // Draw the left side and right side
  mvvline( (y + 1), x, b.ls, (h - 1) );
  mvvline( (y + 1), (x + w), b.rs, (h - 1) );

  // Push to the screen
  refresh( );
}
예제 #4
0
void nccreate(int height, int width, const char *title) {
  int i;

  subwinr = winrows/2-height/2;
  subwinc = wincols/2-width/2;

  /* clear window */
  for(i=0; i<height; i++)
    mvhline(subwinr+i, subwinc, ' ', width);

  /* box() only works around curses windows, so create our own */
  move(subwinr, subwinc);
  addch(ACS_ULCORNER);
  for(i=0; i<width-2; i++)
    addch(ACS_HLINE);
  addch(ACS_URCORNER);

  move(subwinr+height-1, subwinc);
  addch(ACS_LLCORNER);
  for(i=0; i<width-2; i++)
    addch(ACS_HLINE);
  addch(ACS_LRCORNER);

  mvvline(subwinr+1, subwinc, ACS_VLINE, height-2);
  mvvline(subwinr+1, subwinc+width-1, ACS_VLINE, height-2);

  /* title */
  attron(A_BOLD);
  mvaddstr(subwinr, subwinc+4, title);
  attroff(A_BOLD);
}
예제 #5
0
void create_box(WIN *p_win, bool flag)
{	int i, j;
	int x, y, w, h;

	x = p_win->startx;
	y = p_win->starty;
	w = p_win->width;
	h = p_win->height;

	if(flag == TRUE)
	{	mvaddch(y, x, p_win->border.tl);
		mvaddch(y, x + w, p_win->border.tr);
		mvaddch(y + h, x, p_win->border.bl);
		mvaddch(y + h, x + w, p_win->border.br);
		mvhline(y, x + 1, p_win->border.ts, w - 1);
		mvhline(y + h, x + 1, p_win->border.bs, w - 1);
		mvvline(y + 1, x, p_win->border.ls, h - 1);
		mvvline(y + 1, x + w, p_win->border.rs, h - 1);

	}
	else
		for(j = y; j <= y + h; ++j)
			for(i = x; i <= x + w; ++i)
				mvaddch(j, i, ' ');
				
	refresh();

}
예제 #6
0
void WindowManager::drawFrame(uint top, uint left, uint bottom, uint right)
{
	mvaddch(top,left,ACS_ULCORNER); mvaddch(top,right,ACS_URCORNER);
	mvhline(top,left+1,ACS_HLINE,right - left - 1);
	mvvline(top+1,left,ACS_VLINE,bottom - top - 1);
	mvvline(top+1,right,ACS_VLINE,bottom - top - 1);
	mvhline(bottom,left+1,ACS_HLINE,right - left - 1);
	mvaddch(bottom,left,ACS_LLCORNER); mvaddch(bottom,right,ACS_LRCORNER);
}
예제 #7
0
파일: ft_test.c 프로젝트: elenys/2048
static void		print_victory(void)
{
	clear();
	mvprintw(LINES / 2, COLS / 2 - 4, "YOU WIN!");
	mvhline(LINES / 2 - 2, COLS / 2 - 10, 0, 21);
	mvvline(LINES / 2 - 1, COLS / 2 - 10, 0, 4);
	mvvline(LINES / 2 - 1, COLS / 2 + 10, 0, 4);
	mvhline(LINES / 2 + 2, COLS / 2 - 10, 0, 21);
	refresh();
	sleep(3);
}
예제 #8
0
파일: snake.c 프로젝트: macrosheep/snake
int draw_box(int x, int y, int hight, int width)
{
  mvhline(y, x+1, ACS_HLINE, width-1);
  mvhline(y+hight, x+1, ACS_HLINE, width-1);
  mvvline(y+1, x, ACS_VLINE, hight-1);
  mvvline(y+1, x+width, ACS_VLINE, hight-1);
  mvaddch(y, x, ACS_ULCORNER);
  mvaddch(y, x+width, ACS_URCORNER);
  mvaddch(y+hight, x, ACS_LLCORNER);
  mvaddch(y+hight, x+width, ACS_LRCORNER);

  refresh();
}
예제 #9
0
파일: main.c 프로젝트: safiyat/OS_Lab
void rectangle(int y1, int x1, int y2, int x2)
{
	attron(A_BOLD);
	mvhline(y1, x1+1, 0, x2-x1);
	mvhline(y2, x1+1, 0, x2-x1);
	mvvline(y1+1, x1, 0, y2-y1);
	mvvline(y1+1, x2, 0, y2-y1);
	mvaddch(y1, x1, ACS_ULCORNER);
	mvaddch(y1, x2, ACS_URCORNER);
	mvaddch(y2, x1, ACS_LLCORNER);
	mvaddch(y2, x2, ACS_LRCORNER);
	attroff(A_BOLD);
}
예제 #10
0
/*Function to print the desired box at a desired location*/
void printbox(int ux, int uy, boxx b){
	mvvline(uy, ux, 0, b.length);
	mvvline(uy, ux+b.length, 0, b.length);
	mvhline(uy, ux, 0, b.length);
	mvhline(uy+b.length, ux, 0, b.length);
	mvaddch(uy, ux, ACS_ULCORNER);
	mvaddch(uy, ux+b.length, ACS_URCORNER);
	mvaddch(uy+b.length, ux, ACS_LLCORNER);
	mvaddch(uy+b.length, ux+b.length, ACS_LRCORNER);
	if(b.value == ' ')
		mvaddch(uy+b.length/2, ux+b.length/2, b.value);
	else
		mvprintw(uy+b.length/2, ux+b.length/2, "%d", b.value);
}
예제 #11
0
void ClearSpawnQueue(void)
{
    for (int i = 0; i < 15; ++i)
    {
        mvvline(7,106+i,' ',37);
    }
}
예제 #12
0
int main()
{   
	initscr();   //初始化全屏幕,全局的WINDOW* stdscr代表整个屏幕
	printw("hello world.");
	mvprintw(5,6,"hello world.");
	//画出一行的一部分
	mvhline(LINES/2,5,'=',COLS-10);
	//画出一列的一部分
	mvvline(2,4,'|',LINES-4);
	
	//LINES,COLS系统初始化的代表屏幕的行和列,编号从零开始
	mvprintw(LINES/2-1,(COLS-strlen("hello world."))/2-1,"hello world");

        //画出一个框
	box(stdscr,0,0);
	//隐藏光标
	curs_set(0);
	
	refresh();
	//scanw()
	getch();
	endwin();
	
	return 0;
}
void draw(char game_grid[16][16]) {
	mvvline(1, 1, '|', 18);
	mvvline(1, 18, '|', 18);
	mvhline(1, 1, '-', 18);
	mvhline(18, 1, '-', 18);
  int r, c;
	for(r = 0; r < 16; r++) {
		for(c = 0; c < 16; c++) {
			mvaddch(r+2, c+2, game_grid[r][c]);
		}
	}
	mvaddstr(20, 1, "*WASD to play, Q to quit*");
	mvaddstr(21, 5, "**EARLY ALPHA**");
	mvaddstr(22, 6, "***HAS BUGS***");
	refresh();
}
예제 #14
0
void ClearMap(void)
{
    attron(COLOR_PAIR(13));
    for (int i = 0; i < 100-2; ++i)
    {
        mvvline(7,6+i,' ',37);
    }
    attroff(COLOR_PAIR(13));
}
예제 #15
0
int main()
{
	initscr();//��ʼ���ն�
	//border(0,0,0,0,0,0,0,0);
	box(stdscr,0,0);
	mvhline(2,10,'=',20);
	mvvline(2,10,'|',10);
	refresh();
	//wrefrsh(stdscr);
	getch();//�ȴ�һ���ַ�����		
	endwin();//�ͷ��ն�
	return 0;
}
예제 #16
0
int main()
{
	initscr();//全局的WINDOW* stdscr代表整个终端窗口
	//LINES,COLS
	const char* str = "hello, %s!";
	mvhline(LINES/2,5,'-',COLS-10);
	mvvline(2,4,'|',LINES-4);
	mvprintw(LINES/2-1, (COLS-strlen(str))/2-1, str, "芙蓉");
	box(stdscr,0,0);
	curs_set(0);
	refresh();
	getch();
	endwin();
}
예제 #17
0
파일: tile.c 프로젝트: Silberbogen/dvtm-ito
static void
tile(void) {
	unsigned int i, m, n, nx, ny, nw, nh, nm, mw, th;
	Client *c;

	for(n = 0, m = 0, c = clients; c; c = c->next, n++)
		if(c->minimized)
			m++;
	nm = n - m;
	/* window geoms */
	mw = (n == 1 || n - 1 == m) ? waw : screen.mfact * waw;
	/* check if there are at least 2 non minimized clients */
	if(n - 1 > m)
		th = (wah - m) / (nm - 1);

	nx = wax;
	ny = way;
	for(i = 0, c = clients; c; c = c->next, i++) {
		if(i == 0) { /* master */
			nw = mw;
			nh = (n - 1 > m) ? wah : wah - m;
		} else {  /* tile window */
			if(!c->minimized){
				if(i == 1) {
					ny = way;
					nx += mw;
					nw = waw - mw;
					mvvline(ny, nx, ACS_VLINE, wah);
					mvaddch(ny, nx, ACS_TTEE);
					nx++, nw--;
				}
				/* remainder */
				if(m == 0 && i + 1 == n) /* no minimized clients */
					nh = (way + wah) - ny;
				else if(i == nm - 1) /* last not minimized client */
					nh = (way + wah - (n - i - 1)) - ny;
				else
					nh = th;
			} else {
				nh = 1;
				ny = way + wah - (n - i);
			}
			if(i > 1 && nm > 1)
				mvaddch(ny, nx - 1, ACS_LTEE);
		}
		resize(c,nx,ny,nw,nh);
		if(n > 1 && th != wah)
			ny += nh;
	}
}
예제 #18
0
/* paint borders between windows */
void
paint_borders()
{
   int w, h;
   getmaxyx(stdscr, h, w);

   wattron(stdscr, COLOR_PAIR(colors.bars));
   mvhline(1, 0, ACS_HLINE, w);
   if (ui.library->cwin != NULL) {
      mvvline(1, ui.lwidth, ACS_VLINE, h - 2);
      mvaddch(1, ui.lwidth, ACS_TTEE);
   }
   wattroff(stdscr, COLOR_PAIR(colors.bars));
   refresh();
}
예제 #19
0
파일: ui-curses.c 프로젝트: Armavica/vis
static void ui_arrange(Ui *ui, enum UiLayout layout) {
    debug("ui-arrange\n");
    UiCurses *uic = (UiCurses*)ui;
    uic->layout = layout;
    int n = 0, m = !!uic->info[0], x = 0, y = 0;
    for (UiCursesWin *win = uic->windows; win; win = win->next) {
        if (win->options & UI_OPTION_ONELINE)
            m++;
        else
            n++;
    }
    int max_height = uic->height - m;
    int width = (uic->width / MAX(1, n)) - 1;
    int height = max_height / MAX(1, n);
    for (UiCursesWin *win = uic->windows; win; win = win->next) {
        if (win->options & UI_OPTION_ONELINE)
            continue;
        n--;
        if (layout == UI_LAYOUT_HORIZONTAL) {
            int h = n ? height : max_height - y;
            ui_window_resize(win, uic->width, h);
            ui_window_move(win, x, y);
            y += h;
        } else {
            int w = n ? width : uic->width - x;
            ui_window_resize(win, w, max_height);
            ui_window_move(win, x, y);
            x += w;
            if (n)
                mvvline(0, x++, ACS_VLINE, max_height);
        }
    }

    if (layout == UI_LAYOUT_VERTICAL)
        y = max_height;

    for (UiCursesWin *win = uic->windows; win; win = win->next) {
        if (!(win->options & UI_OPTION_ONELINE))
            continue;
        ui_window_resize(win, uic->width, 1);
        ui_window_move(win, 0, y++);
    }
}
예제 #20
0
int main(void)
{
	int maxy,maxx,halfy,x,len;
	initscr();

	getmaxyx(stdscr,maxy,maxx);
	halfy = maxy >> 1;				/* y/2 */
	len = 1;

	for(x=0;x<maxx;x++)
	{
		mvvline(halfy-len,x,0,len+len);
		if( !(x % 7)) len++;
	}
	refresh();
	getch();

	endwin();
	return 0;
}
예제 #21
0
파일: line_agent.c 프로젝트: levenkov/olver
static TACommandVerdict mvvline_cmd(TAThread thread,TAInputStream stream)
{
    chtype ch;
    int n;
    int y;
    int x;
    int res;
    
    y = readInt(&stream);
    x = readInt(&stream);
    ch = readChType(&stream);
    n = readInt(&stream);
    
    START_TARGET_OPERATION(thread);
    
    res = mvvline(y, x, ch, n);
    
    END_TARGET_OPERATION(thread);
    
    writeInt(thread, res);
    sendResponse(thread);
    
    return taDefaultVerdict;
}
예제 #22
0
파일: main.cpp 프로젝트: ijat/rF3.Calendar
void list_events(int day_filter, int mon_filter, int year_filter) {
	unsigned int current_page = 1, max_page, index_page = 0;
	unsigned int mod = myVector.size() % 12;
	int key, n_keys = 0, selected_event_index;
	char type_keys[66];

	erase();
	titlebar();
	refresh();
	resize_term(40, 80);

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "List Event(s)");
	mvprintw(3, 1, "-------------");

	// Draw table
	mvvline(5, 1, 0, 29);
	mvvline(5, 6, 0, 29);
	mvvline(5, 51, 0, 29);
	mvvline(5, 70, 0, 29);
	mvvline(5, 78, 0, 29);
	mvhline(5, 1, 0, 78);
	mvhline(7, 1, 0, 78);
	mvhline(33, 1, 0, 78);

	// Print out some text
	mvprintw(6, 3, "No");
	mvprintw(6, 8, "Event Name");
	mvprintw(6, 53, "Date");
	mvprintw(6, 72, "Time");

	refresh();

	WINDOW *wID, *wNAME, *wDATE, *wTIME, *wDET, *wSTAT;

	wID = newwin(25, 4, 8, 2);
	wrefresh(wID);

	wNAME = newwin(25, 42, 8, 8);
	wrefresh(wNAME);

	wDATE = newwin(25, 18, 8, 52);
	wrefresh(wDATE);

	wTIME = newwin(25, 7, 8, 71);
	wrefresh(wTIME);

	wDET = newwin(4, 78, 36, 1);
	wattron(wDET, COLOR_PAIR(6));
	mvwprintw(wDET, 0, 0, "Press LEFT or RIGHT to change the page. Type any event number and press E to \nedit, D to delete, R to swap two events or ENTER for more details.\nOr you can press S to sort all the events. To go back, press ESC.");
	wrefresh(wDET);

	wSTAT = newwin(1, 78, 39, 1);
	wrefresh(wSTAT);

	// Declare variable for filter purpose
	std::vector<my_event> filter;
	std::vector<my_event> *list;
	my_event temp;

	// Apply filter for saved events. Copy data to the temporary local vector and print to the list.
	// Optional function. Maybe not implemented for now.
	// Since the code is identical, only the logical expression different. So it can be simpified but not for now.
	if (day_filter != 0 || mon_filter != 0 || year_filter != 0) {
		for (unsigned int z = 0; z < myVector.size(); z++) {
			if (year_filter != 0) {
				if (myVector[z].year == year_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (mon_filter != 0) {
				if (myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0) {
				if (myVector[z].day == day_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0 && mon_filter != 0) {
				if (myVector[z].day == day_filter && myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (year_filter != 0 && mon_filter != 0) {
				if (myVector[z].year == year_filter && myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0 && mon_filter != 0 && year_filter != 0) {
				if (myVector[z].day == day_filter && myVector[z].nmon == mon_filter && myVector[z].year == year_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
		}
		list = &filter;
	}
	else list = &myVector;

	if (mod != 0) max_page = (int)(ceil((*list).size() / 12)) + 1;
	else max_page = (*list).size() / 12;

	while (1) {

		werase(wID);
		werase(wNAME);
		werase(wDATE);
		werase(wTIME);
		mvprintw(34, 1, "Page: %i/%i", current_page, max_page);

		int n_line = 1;
		for (unsigned int i = index_page; i < index_page + 12; i++) {
			if (i < (*list).size()) {
				mvwprintw(wID, n_line, 1, "%i", i + 1);
				mvwprintw(wNAME, n_line, 0, "%s", (*list)[i].name);
				mvwprintw(wDATE, n_line, 1, "%i %s %i", (*list)[i].day, mon_name((*list)[i].nmon), (*list)[i].year);
				wformatted_time(wTIME, n_line, 1, (*list)[i].hour, (*list)[i].min);
				wrefresh(wID);
				wrefresh(wNAME);
				wrefresh(wDATE);
				wrefresh(wTIME);
				n_line += 2;
			}
		}

		key = getch();
		//mvprintw(39, 1, "%i", key);

		if (key == 115 || key == 83) {
			werase(wDET);
			wattron(wDET, COLOR_PAIR(6));
			mvwprintw(wDET, 0, 0, "Press 1 to sort by Day, 2 to sort by Month or 3 to sort by Year.\nPress ESC to go back.");
			wattroff(wDET, COLOR_PAIR(6));
			wrefresh(wDET);
			werase(wSTAT);
			while (1) {
				key = getch();
				if (!(key >= 49 && key <= 51) || key != 27) {
					werase(wDET);
					wattron(wDET, COLOR_PAIR(5));
					mvwprintw(wDET, 0, 0, "Invalid selection...");
					wattroff(wDET, COLOR_PAIR(5));
					wrefresh(wDET);
				}
				if (key == 49) {
					std::sort(myVector.begin(), myVector.end(), SortDay());
					break;
				}
				if (key == 50) {
					std::sort(myVector.begin(), myVector.end(), SortMonth());
					break;
				}
				if (key == 51) {
					std::sort(myVector.begin(), myVector.end(), SortYear());
					break;
				}
				if (key == 27) break;
			}
			break;
		}

		if ((key >= 48 && key <= 57) || key == 8) {
			if (key >= 48 && key <= 57) {
				if (n_keys <= 66) {
					werase(wSTAT);
					type_keys[n_keys] = char(key);
					n_keys++;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);		// Show the user for any typed numbers
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
			}
			if (key == 8) {
				if (n_keys > 1) {
					werase(wSTAT);
					type_keys[n_keys] = ' ';
					type_keys[n_keys - 1] = ' ';
					n_keys--;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					n_keys = 0;
				}
			}
		}

		// User pressed enter/E/D (all caps)
		if (key == 13 || key == 100 || key == 68 || key == 69 || key == 101 || key == 82 || key == 114) {
			if (n_keys > 0) {
				selected_event_index = atol(&type_keys[0]);
				if (selected_event_index >= 1 && selected_event_index <= int((*list).size())) break;
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					werase(wDET);
					wattron(wDET, COLOR_PAIR(5));
					mvwprintw(wDET, 0, 0, "Invalid number or out of range.\nPlease try again...");
					wattroff(wDET, COLOR_PAIR(5));
					wrefresh(wDET);
					for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
					n_keys = 0;																// Reset the number of key typed
				}
			}
		}

		if (key == 27) menu();

		if (key == KEY_RIGHT) {
			if (current_page < max_page) {
				index_page += 12;
				current_page++;
				continue;
			}
		}

		if (key == KEY_LEFT) {
			if (current_page > 1) {
				index_page -= 12;
				current_page--;
				continue;
			}
		}

		if (key == KEY_F(2)) {
			mvprintw(5, 1, "%i", myVector.size());
			//refresh();
		}

		if (key == KEY_F(1)) exit(0);
	}

	if (key == 13) data.show_details(selected_event_index - 1);
	if (key == 100 || key == 68) data.delete_event(selected_event_index - 1);
	if (key == 101 || key == 69) data.edit_event(selected_event_index - 1);

	// Sorting Lab 4
//	if (key == 82 || key == 114) {
		
	//}

	// Swapping Lab 3
	if (key == 82 || key == 114) {
		werase(wDET);
		wattron(wDET, COLOR_PAIR(6));
		mvwprintw(wDET, 0, 0, "Now enter the second event number to replace.\nPress ESC to cancel.");
		wattroff(wDET, COLOR_PAIR(6));
		wrefresh(wDET);
		werase(wSTAT);
		mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
		wrefresh(wSTAT);
		for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
		n_keys = 0;
		while (1) {
			key = getch();
			if (key == 27) break;
			if (key >= 48 && key <= 57) {
				if (n_keys <= 66) {
					werase(wSTAT);
					type_keys[n_keys] = char(key);
					n_keys++;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);		// Show the user for any typed numbers
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
			}
			if (key == 8) {
				if (n_keys > 1) {
					werase(wSTAT);
					type_keys[n_keys] = ' ';
					type_keys[n_keys - 1] = ' ';
					n_keys--;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					n_keys = 0;
				}
			}

			if (key == 13 || key == 100) {
				if (n_keys > 0) {
					int sec_selected_event_index;
					sec_selected_event_index = atol(&type_keys[0]);
					if (sec_selected_event_index >= 1 && sec_selected_event_index <= int((*list).size()) && selected_event_index != sec_selected_event_index) {
						/*mvwprintw(wSTAT, 0, 0, "selected: %i, second: %i",selected_event_index,sec_selected_event_index);
						wrefresh(wSTAT);
						getch();*/
						swap(selected_event_index - 1, sec_selected_event_index - 1);
						break;
					}
					else {
						werase(wSTAT);
						wrefresh(wSTAT);
						werase(wDET);
						wattron(wDET, COLOR_PAIR(5));
						mvwprintw(wDET, 0, 0, "Invalid number or out of range.\nPlease try again...");
						wattroff(wDET, COLOR_PAIR(5));
						wrefresh(wDET);
						for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
						n_keys = 0;																// Reset the number of key typed
						werase(wSTAT);
						mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
						wrefresh(wSTAT);
					}
				}
			}
		}

	}

	list_events();
}
예제 #23
0
파일: ui.c 프로젝트: Lekensteyn/radeontop
void present(const unsigned int ticks, const char card[], unsigned int color) {

	printf(_("Collecting data, please wait....\n"));

	// This does not need to be atomic. A delay here is acceptable.
	while(!results)
		usleep(16000);

	initscr();
	noecho();
	halfdelay(10);
	curs_set(0);
	clear();

	start_color();
	init_pair(1, COLOR_GREEN, COLOR_BLACK);
	init_pair(2, COLOR_RED, COLOR_BLACK);
	init_pair(3, COLOR_CYAN, COLOR_BLACK);
	init_pair(4, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(5, COLOR_YELLOW, COLOR_BLACK);

	const unsigned int bigh = 23;

	unsigned int w, h;
	getmaxyx(stdscr, h, w);

	const unsigned int hw = w/2;

	attron(A_REVERSE);
	mvhline(0, 0, ' ', w);
	printcenter(0, w, _("radeontop %s, running on %s, %u samples/sec"),
			VERSION, card, 	ticks);
	attroff(A_REVERSE);

	while(1) {

		move(2, 0);
		clrtobot();

		// Again, no need to protect these. Worst that happens is a slightly
		// wrong number.
		float ee = 100.0 * (float) results->ee / ticks;
		float vgt = 100.0 * (float) results->vgt / ticks;
		float gui = 100.0 * (float) results->gui / ticks;
		float ta = 100.0 * (float) results->ta / ticks;
		float tc = 100.0 * (float) results->tc / ticks;
		float sx = 100.0 * (float) results->sx / ticks;
		float sh = 100.0 * (float) results->sh / ticks;
		float spi = 100.0 * (float) results->spi / ticks;
		float smx = 100.0 * (float) results->smx / ticks;
		float sc = 100.0 * (float) results->sc / ticks;
		float pa = 100.0 * (float) results->pa / ticks;
		float db = 100.0 * (float) results->db / ticks;
		float cr = 100.0 * (float) results->cr / ticks;
		float cb = 100.0 * (float) results->cb / ticks;
		float vram = 100.0 * (float) results->vram / vramsize;
		float vrammb = results->vram / 1024.0f / 1024.0f;
		float vramsizemb = vramsize / 1024.0f / 1024.0f;

		mvhline(3, 0, ACS_HLINE, w);
		mvvline(1, (w/2) + 1, ACS_VLINE, h);
		mvaddch(3, (w/2) + 1, ACS_PLUS);

		if (color) attron(COLOR_PAIR(1));
		percentage(2, w, gui);
		printright(2, hw, _("Graphics pipe %6.2f%%"), gui);
		if (color) attroff(COLOR_PAIR(1));

		unsigned int start = 4;

		percentage(start, w, ee);
		printright(start++, hw, _("Event Engine %6.2f%%"), ee);

		// Enough height?
		if (h > bigh) start++;

		if (color) attron(COLOR_PAIR(2));
		percentage(start, w, vgt);
		printright(start++, hw, _("Vertex Grouper + Tesselator %6.2f%%"), vgt);
		if (color) attroff(COLOR_PAIR(2));

		// Enough height?
		if (h > bigh) start++;

		if (color) attron(COLOR_PAIR(3));
		percentage(start, w, ta);
		printright(start++, hw, _("Texture Addresser %6.2f%%"), ta);

		// This is only present on R600
		if (bits.tc) {
			percentage(start, w, tc);
			printright(start++, hw, _("Texture Cache %6.2f%%"), tc);
		}
		if (color) attroff(COLOR_PAIR(3));

		// Enough height?
		if (h > bigh) start++;

		if (color) attron(COLOR_PAIR(4));
		percentage(start, w, sx);
		printright(start++, hw, _("Shader Export %6.2f%%"), sx);

		percentage(start, w, sh);
		printright(start++, hw, _("Sequencer Instruction Cache %6.2f%%"), sh);

		percentage(start, w, spi);
		printright(start++, hw, _("Shader Interpolator %6.2f%%"), spi);

		// only on R600
		if (bits.smx) {
			percentage(start, w, smx);
			printright(start++, hw, _("Shader Memory Exchange %6.2f%%"), smx);
		}
		if (color) attroff(COLOR_PAIR(4));

		// Enough height?
		if (h > bigh) start++;

		percentage(start, w, sc);
		printright(start++, hw, _("Scan Converter %6.2f%%"), sc);

		percentage(start, w, pa);
		printright(start++, hw, _("Primitive Assembly %6.2f%%"), pa);

		// Enough height?
		if (h > bigh) start++;

		if (color) attron(COLOR_PAIR(5));
		percentage(start, w, db);
		printright(start++, hw, _("Depth Block %6.2f%%"), db);

		percentage(start, w, cb);
		printright(start++, hw, _("Color Block %6.2f%%"), cb);

		// Only present on R600
		if (bits.cr) {
			percentage(start, w, cr);
			printright(start++, hw, _("Clip Rectangle %6.2f%%"), cr);
		}
		if (color) attroff(COLOR_PAIR(5));

		// Enough height?
		if (h > bigh) start++;

		if (bits.vram) {
			if (color) attron(COLOR_PAIR(2));
			percentage(start, w, vram);
			printright(start++, hw, _("%.0fM / %.0fM VRAM %6.2f%%"),
					vrammb, vramsizemb, vram);
			if (color) attroff(COLOR_PAIR(2));
		}

		refresh();

		int c = getch();
		if (c == 'q' || c == 'Q') break;
		if (c == 'c' || c == 'C') color = !color;
	}

	endwin();
}
예제 #24
0
파일: grid.c 프로젝트: gridsystem/dvtmx
static void grid(void)
{
	unsigned int i, m, nm, n, nx, ny, nw, nh, aw, ah, cols, rows;
	Client *c;

	for (n = 0, m = 0, c = nextvisible(clients); c; c = nextvisible(c->next), n++)
		if (c->minimized)
			m++;
	/* number of non minimized windows */
	nm = n - m;
	/* grid dimensions */
	for (cols = 0; cols <= nm / 2; cols++)
		if (cols * cols >= nm)
			break;
	rows = (cols && (cols - 1) * cols >= nm) ? cols - 1 : cols;
	/* window geoms (cell height/width) */
	nh = (wah - m) / (rows ? rows : 1);
	nw = waw / (cols ? cols : 1);
	for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next), i++) {
		if (!c->minimized) {
			/* if there are less clients in the last row than normal adjust the
			 * split rate to fill the empty space */
			if (rows > 1 && i == (rows * cols) - cols
			    && (nm - i) <= (nm % cols))
				nw = waw / (nm - i);
			nx = (i % cols) * nw + wax;
			ny = (i / cols) * nh + way;
			/* adjust height/width of last row/column's windows */
			ah = (i >= cols * (rows - 1)) ? wah - m - nh * rows : 0;
			/* special case if there are less clients in the last row */
			if (rows > 1 && i == nm - 1 && (nm - i) < (nm % cols))
				/* (n % cols) == number of clients in the last row */
				aw = waw - nw * (nm % cols);
			else
				aw = ((i + 1) % cols ==
				      0) ? waw - nw * cols : 0;
			if (i % cols) {
				mvvline(ny, nx, THEME_VERT_CHAR, nh + ah);
				/* if we are on the first row, or on the last one and there are fewer clients
				 * than normal whose border does not match the line above, print a top tree char
				 * otherwise a plus sign. */
				if (i <= cols
				    || (i >= rows * cols - cols && nm % cols
					&& (cols - (nm % cols)) % 2))
					mvaddch(ny, nx, THEME_TT_CHAR);
				else
					mvaddch(ny, nx, THEME_PLUS_CHAR);
				nx++, aw--;
			}
		} else {
			if (i == nm) {	/* first minimized client */
				ny = way + wah - m;
				nx = wax;
				nw = waw;
				nh = 1;
				aw = 0;
				ah = 0;
			} else
				ny++;
		}
		resize(c, nx, ny, nw + aw, nh + ah);
	}
}
예제 #25
0
파일: dochttx.c 프로젝트: jwilk/dochttx
int main(int argc, char **argv)
{
    int region = -1;
    const char *device = default_device;
    int opt;
    enum {
        OPT_DUMMY = CHAR_MAX,
        OPT_VERSION
    };
    static struct option long_options[] = {
        {"help", no_argument, NULL, 'h'},
        {"version", no_argument, NULL, OPT_VERSION},
        {NULL, 0, NULL, 0}
    };
    while ((opt = getopt_long(argc, argv, "d:l:h", long_options, NULL)) != -1)
        switch (opt)
        {
        case 'd':
            device = optarg;
            break;
        case 'l':
            region = dochttx_region_for_lang(optarg);
            if (region < 0) {
                errno = EINVAL;
                perror("dochttx: -l");
                exit(EXIT_FAILURE);
            }
            break;
        case 'h':
            long_usage(stdout);
            exit(EXIT_SUCCESS);
        case OPT_VERSION:
            print_version();
            exit(EXIT_SUCCESS);
        default: /* '?' */
            usage(stderr);
            exit(EXIT_FAILURE);
        }
    if (optind != argc) {
        usage(stderr);
        exit(EXIT_FAILURE);
    }

    int rc = dochttx_locale_init();
    if (rc < 0) {
        perror("dochttx: locale initialization failed");
        return EXIT_FAILURE;
    }

    if (region < 0)
        region = dochttx_region_for_locale();
    if (region < 0)
        region = dochttx_region_for_lang("en");
    assert(region >= 0);

    struct dochttx_vbi_state* vbi = dochttx_vbi_open(device, region);
    if (vbi == NULL)
        return EXIT_FAILURE;

    dochttx_ncurses_init();

    mvvline(0, 41, ACS_VLINE, 25);
    for (int y = 0; y < 25; y++)
        mvhline(y, 0, ACS_BOARD, 41);
    mvhline(25, 0, ACS_HLINE, COLS);
    mvaddch(25, 41, ACS_BTEE);

    vbi_event_handler_register(vbi->dec, VBI_EVENT_TTX_PAGE, on_event_ttx_page, NULL);

    vbi_pgno req_pgno = 0x100;
    vbi_subno req_subno = VBI_ANY_SUBNO;
    draw_looking_for(req_pgno, req_subno);
    bool req_drawn = false;

    struct input input = {
        .text = {0},
        .position = 0,
        .status = INPUT_NORMAL,
    };
    draw_input(&input);

    refresh();

    while (true) {
        struct pollfd fds[2] = {
            { .fd = STDIN_FILENO, .events = POLLIN },
            { .fd = vbi->fd, .events = POLLIN, .revents = POLLIN },
        };
예제 #26
0
static void
fibonacci(int s) {
	unsigned int nx, ny, nw, nnw, nh, nnh, i, n, m, nm, mod;
	Client *c;

	for(n = 0, m = 0, c = clients; c; c = c->next,n++)
		if(c->minimized)
			m++;
	/* number of non minimized windows */
	nm = n - m;

	/* initial position and dimensions */
	nx = wax;
	ny = way;
	nw = (n == 1) ? waw : screen.mfact * waw;
	/* don't waste space dviding by 2 doesn't work for odd numbers
	 * plus we need space for the border too. therefore set up these
	 * variables for the next new width/height
	 */
	nnw = waw - nw - 1;
	nnh = nh = (wah - m); /* leave space for the minimized clients */

	/* set the mod factor, 2 for dwindle, 4 for spiral */
	mod = s ? 4 : 2;

	for(i = 0, c = clients; c; c = c->next,i++) {
		if(!c->minimized) {
			/* dwindle: even case, spiral: case 0*/
			if(i % mod == 0) {
				if (i) {
					if (s) {
						nh = nnh;
						ny -= nh;
					} else {
						ny += nh;
						nh = nnh;
					}
					/* don't adjust the width for the last non-minimized client */
					if(i < nm - 1) {
						nw  /= 2;
						nnw -= nw + 1;
					}
					mvaddch(ny, nx - 1, ACS_LTEE);
				}
			} else if(i % mod == 1) { /* dwindle: odd case, spiral: case 1*/
				nx += nw;
				mvvline(ny, nx, ACS_VLINE, nh);
				mvaddch(ny, nx, ACS_TTEE);
				++nx;
				nw = nnw;
				/* don't adjust the height for the last non-minimized client */
				if(i < nm - 1) {
					nh /= 2;
					nnh -= nh;
				}
			} else if(i % mod == 2 && s) { /* spiral: case 2*/
				ny += nh;
				nh = nnh;
				/* don't adjust the width for the last non-minimized client */
				if(i < nm - 1) {
					nw  /= 2;
					nnw -= nw + 1;
					nx += nnw;
					mvvline(ny, nx, ACS_VLINE, nh);
					mvaddch(ny, nx, ACS_TTEE);
					++nx;
				} else {
					mvaddch(ny, nx - 1, ACS_LTEE);
				}
			} else if(s) { /* spiral: case 3*/
				nw = nnw;
				nx -= nw + 1; /* border */
				/* don't adjust the height for the last non-minimized client */
				if(i < nm - 1) {
					nh /= 2;
					nnh -= nh;
					ny += nnh;
				}
				mvaddch(ny, nx - 1, ACS_LTEE);
			}
		} else {
			nh = 1;
			nw = waw;
			nx = wax;
			ny = way + wah - (n - i);
		}

		resize(c,nx,ny,nw,nh);
	}
}
예제 #27
0
main() {
  object scr; int i = 0,cont=0; bool end=false;
  initscr();
  start_color();
  init_pair(1,COLOR_BLUE,COLOR_BLACK);
  keypad(stdscr,true);
  noecho();
  curs_set(0);
  getmaxyx(stdscr,scr.y,scr.x);
  object b1={scr.x-2,scr.y/2,0,false,false},b2={1,scr.y/2,0,false,false},b={scr.x/2,scr.y/2,0,false,false};
  mvprintw(4,0,"\t           oooooooooo                                        \n"
               "\t           888    888  ooooooo    ooooooo    oooooooo8       \n"
               "\t           888oooo88 888     888 888   888  888    88o       \n"
               "\t           888       888     888 888   888   888oo888o       \n"
               "\t          o888o        88ooo88  o888o o888o 888     888      \n"
               "\t                                             888ooo888     \n\n"
               "\t Any questions please send me at [email protected]     \n"
               "\t \t\t\tPlayer 1 your controls are 'a' and 'q'                \n"
               "\t \t\t\tPlayer 2 your controls are the arrows of the keyboard \n"
               "\t \t\t\tPush ANY key to start, 'p' for pause and ESC to quit" ); 
  getch();
  for (nodelay(stdscr,1); !end; usleep(4000)) {
    if (++cont%16==0){
      if ((b.y==scr.y-1)||(b.y==1))
        b.movver=!b.movver;
      if ((b.x>=scr.x-2)||(b.x<=2)){
        b.movhor=!b.movhor;
        if ((b.y==b1.y-1)||(b.y==b2.y-1)) {
          b.movver=false;
        } else if ((b.y==b1.y+1)||(b.y==b2.y+1)) {
          b.movver=true;
        } else if ((b.y != b1.y) && (b.y != b2.y)) {
          (b.x>=scr.x-2) ? b1.c++: b2.c++;
          b.x=scr.x/2;
          b.y=scr.y/2;
        }
      }
      b.x=b.movhor ? b.x+1 : b.x-1;
      b.y=b.movver ? b.y+1 : b.y-1;

      if (b1.y<=1)
        b1.y=scr.y-2;
      if (b1.y>=scr.y-1)
        b1.y=2;
      if (b2.y<=1)
        b2.y=scr.y-2;
      if (b2.y>=scr.y-1)
        b2.y=2;
    }
    switch (getch()) {
      case KEY_DOWN: b1.y++; break;
      case KEY_UP:   b1.y--; break;
      case 'q':      b2.y--; break;
      case 'a':      b2.y++; break;
      case 'p':      getchar(); break;
      case 0x1B:    endwin(); end++; break;
    }
    erase();
    mvprintw(2,scr.x/2-2,"%i | %i",b1.c,b2.c);
    mvvline(0,scr.x/2,ACS_VLINE,scr.y);
    attron(COLOR_PAIR(1));
    mvprintw(b.y,b.x,"o");
    for(i=-1;i<2;i++){
      mvprintw(b1.y+i,b1.x,"|");
      mvprintw(b2.y+i,b2.x,"|");}
    attroff(COLOR_PAIR(1));
  }
}
예제 #28
0
파일: snake.c 프로젝트: kahn04/snake
int main(int argc, char *argv[])
{
    int ch;

    initscr();
    start_color();
    cbreak();
    keypad(stdscr, TRUE);
    noecho();
    curs_set(0);
    init_pair(1, COLOR_CYAN, COLOR_BLACK);

    attron(COLOR_PAIR(1));
    //画边
    mvaddch(1, 0, '+');
    mvaddch(1, COLS-1, '+');
    mvaddch(LINES-1, COLS-1, '+');
    mvaddch(LINES-1, 0, '+');
    mvhline(1, 1, '-', COLS-1-1);
    mvhline(LINES-1, 1, '-', COLS-1-1);
    mvvline(2, 0, '|', LINES-2-1);
    mvvline(2, COLS-1, '|', LINES-2-1);

    refresh();
    attroff(COLOR_PAIR(1));

    // 来条蛇
    SNAKE snake;
    init_snake(&snake);
    draw_whole_snake(&snake);
    
    // 初始豆儿
    int *food;
    food = random_food(&snake);
    //mvaddch(food[1], food[0], '*');
    draw_food(food);

    int d;
    int i;
    now_time=0;
    while (1)
    {
        if(ioctl(0,FIONREAD,&i)<0)
        {
            printf("ioctl failed, error=%d\n ",errno);
            break;
        }
        if(!i)  // 小蛇自动跑部分
        {
            usleep(time_rate);
            now_time = now_time + time_rate;
            if (!(now_time < speed))
            {
                now_time = 0;
                if (snake_move(&snake, food))
                    break;
            }
            continue;
        }
        now_time = 0;
        ch = getch();
        if (ch < 258 || ch > 261)
            continue;
        if ( ch+snake.d != KEY_LEFT+KEY_UP )
        {
            d = ch - snake.d;
            if ( d == 1 || d == -1)
                continue;
        }
        snake.d = ch;

        if (snake_move(&snake, food))
            break;

    }
    getch();
    endwin();
    return 0;
}