示例#1
0
box box_rep::subbox (int i) { (void) i; return box (); }
示例#2
0
void p32000()
{
srand(time(NULL));
otgram=32000;
wclear(pion2up);
box(pion2up, 0, 0);
wrefresh(pion2up);
do{
pytnr=(rand() % 10);
}while(pytnr==oldpytnr);
switch(pytnr)
{
case 0:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 72)/2), "%s", "Jak nazywa siê partnerka agenta Foxa Muldera z serialu \"Z Archiwum X\"?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 10)/2), "%s", "Vicky Vale");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 11)/2), "%s", "Dana Scully");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 9)/2), "%s", "Lois Lane");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 16)/2), "%s", "Dorothy Michaels");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=2;
break;
}
case 1:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 48)/2), "%s", "Jak dlugo \"zyje\" czerwona krwinka u czlowieka?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 12)/2), "%s", "okolo 30 dni");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 13)/2), "%s", "okolo 120 dni");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 13)/2), "%s", "okolo 250 dni");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 13)/2), "%s", "okolo 360 dni");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=2;
break;
}
case 2:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 10)/2), "%s", "Zgodnie z krzywa Phillipsa, gdy spada inflacja, bezrobocie:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 12)/2), "%s", "tez spada");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 19)/2), "%s", "zanika");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 20)/2), "%s", "rosnie");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 16)/2), "%s", "nie zmienia sie");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=2;
break;
}
case 3:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 38)/2), "%s", "Jak brzmi inna nazwa kwasu butanowego?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 6)/2), "%s", "octowy");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 10)/2), "%s", "stearynowy");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 7)/2), "%s", "maslowy");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 8)/2), "%s", "siarkowy");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=3;
break;
}
case 4:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 39)/2), "%s", "Ktory z pradow oceanicznych jest zimny?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 9)/2), "%s", "Kuro Siwo");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 10)/2), "%s", "Golfsztrom");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 11)/2), "%s", "Brazylijski");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 23)/2), "%s", "Dryf Wiatrow Zachodnich");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=4;
break;
}
case 5:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 58)/2), "%s", "\"Reszta jest milczeniem\" to ostatnie slowa umierajacego:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 7)/2), "%s", "Makbeta");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 10)/2), "%s", "Klaudiusza");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 10)/2), "%s", "Poloniusza");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 7)/2), "%s", "Hamleta");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=4;
break;
}
case 6:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 26)/2), "%s", "Samuel Morse z zawodu byl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 10)/2), "%s", "inzynierem");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 8)/2), "%s", "malarzem");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 9)/2), "%s", "zeglarzem");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 12)/2), "%s", "matematykiem");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=2;
break;
}
case 7:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 45)/2), "%s", "Z ktorej dynastii pochodzila krolowa Jadwiga?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 7)/2), "%s", "Piastow");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 11)/2), "%s", "Jagiellonow");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 11)/2), "%s", "Andegawenow");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 12)/2), "%s", "Przemyslidow");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=3;
break;
}
case 8:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 52)/2), "%s", "Ktory kontynent jest ojczyzna wiêkszosci odmian kawy?");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 4)/2), "%s", "Azja");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 6)/2), "%s", "Europa");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 6)/2), "%s", "Afryka");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 18)/2), "%s", "Ameryka Poludniowa");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=3;
break;
}
case 9:
{
odpa=1;
odpb=1;
odpc=1;
odpd=1;
mvwprintw(pion2up, (y2u/2)-4, ((x2u - 25)/2), "%s", "O to pytanie za 32000 zl:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)-2, ((x2u - 56)/2), "%s", "Kraj z ruinami starozytnej Kartaginy - rywalki Rzymu to:");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2), ((x2u - 5)/2), "%s", "Libia");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+1, ((x2u - 5)/2), "%s", "Egipt");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+2, ((x2u - 8)/2), "%s", "Algieria");
wrefresh(pion2up);
usleep(1500000);
mvwprintw(pion2up, (y2u/2)+3, ((x2u - 7)/2), "%s", "Tunezja");
wrefresh(pion2up);
usleep(1500000);
prawidlodp=4;
break;
}
default: break;
}
}
示例#3
0
void NcursesResize(Connection *conn, const char *file)
{
	if (has_colors() == TRUE) {
		start_color();

		init_pair(1, COLOR_WHITE, COLOR_BLUE);
		init_pair(2, COLOR_BLACK, COLOR_CYAN);
		init_pair(3, COLOR_WHITE, COLOR_MAGENTA);
		init_color(COLOR_WHITE, 500, 500, 500);
		init_pair(4, COLOR_BLACK, COLOR_WHITE);
		init_pair(5, COLOR_BLACK, COLOR_GREEN);
		init_pair(6, COLOR_CYAN, COLOR_CYAN);

		bkgd(COLOR_PAIR(2));
		attron(A_REVERSE);
	}

	curs_set(0);
	noecho();

	getmaxyx(stdscr, maxy, maxx);
	halfx = maxx >> 1;
	halfy = maxy >> 1;

	mvaddstr(maxy - 2, maxx - 17, "Press ? for help");

	/* debug
	   mvprintw(maxy - 4, maxx - 17, "maxy = %d", maxy);
	   mvprintw(maxy - 3, maxx - 17, "maxx = %d", maxx);
	 */

	refresh();

	// title window
	title = newwin(3 ,maxx - 2, 1, 1);
	if (title == NULL) {
		addstr("Unable to allocate memory for title window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(title, COLOR_PAIR(1));
	box(title, '|', '=');
	NcursesCenter(title, 1, banner);
	wrefresh(title);

	// body window (y size has to be tweaked by screen size)
	//border_body = newwin(((2 * maxy) / 3) - 5, maxx - 2, 5, 1);
	border_body = newwin(((2 * maxy) / 3) - 2, maxx - 2, 5, 1);
	if (border_body == NULL) {
		addstr("Unable to allocate memory for border body window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(border_body, COLOR_PAIR(1));
	box(border_body, '|', '=');
	wrefresh(border_body);

	body = newpad(maxy * 4, maxx - 2);
	if (body == NULL) {
		addstr("Unable to allocate memory for body window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(body, COLOR_PAIR(1));

	// usage window
	//border_usage = newwin((maxy / 2) - 5, maxx / 2, 
	/*border_usage = newwin((maxy / 2) + 1, maxx / 2 + 13, 
	  (maxy / 4) - 4, (maxx / 4) - 6);
	 */
	border_usage = newwin((maxy / 2) - 1, maxx / 2 + 13, 
			(maxy / 4) - 4, (maxx / 4) - 6);
	if (border_usage == NULL) {
		addstr("Unable to allocate memory for border usage window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}		

	wbkgd(border_usage, COLOR_PAIR(3));
	box(border_usage, '|', '=');

	/*usage = newwin((maxy / 2) - 1, (maxx / 2) + 11, 
	  (maxy / 4) - 3, (maxx / 4) - 5);
	 */
	usage = newwin((maxy / 2) - 3, (maxx / 2) + 11, 
			(maxy / 4) - 3, (maxx / 4) - 5);
	if (usage == NULL) {
		addstr("Unable to allocate memory for usage window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(usage, COLOR_PAIR(3));
	getmaxyx(usage, usage_maxy, usage_maxx);

	while (*help_ptr) {
		getyx(usage, usage_y, usage_x);
		if (*help_ptr == ' ')
			if (usage_maxx - usage_x < 12) waddch(usage, '\n');
		waddch(usage, *help_ptr);
		help_ptr++;
	}

	// console window
	border_console = newwin(5, maxx / 3, maxy - 8, maxx / 3);
	if (border_console == NULL) {
		addstr("Unable to allocate memory for border console window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(border_console, COLOR_PAIR(5));

	console = newwin(3, (maxx / 3) - 2, (maxy - 8 + 1), (maxx / 3) + 1);
	if (console == NULL) {
		addstr("Unable to allocate memory for console window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}	

	wbkgd(console, COLOR_PAIR(4));
	box(console, '*', '*');

	// add window
	add = SUBWINDOWS;
	if (add == NULL) {
		addstr("Unable to allocate memory for add window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}

	wbkgd(add, COLOR_PAIR(1));
	box(add, '|', '=');
	NcursesCenter(add, 0, "Add Record");

	// resize window
	resize = SUBWINDOWS;
	if (resize == NULL) {
		addstr("Unable to allocate memory for resize window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}

	wbkgd(resize, COLOR_PAIR(1));
	box(resize, '|', '=');
	NcursesCenter(resize, 0, "Resize to");

	// find window
	find = SUBWINDOWS;
	if (find == NULL) {
		addstr("Unable to allocate memory for find window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}

	wbkgd(find, COLOR_PAIR(1));
	box(find, '|', '=');
	NcursesCenter(find, 0, "Find");

	// create window
	create = SUBWINDOWS;
	if (create == NULL) {
		addstr("Unable to allocate memory for find window");
		DatabaseClose(conn);
		endwin();
		exit(1);
	}

	wbkgd(create, COLOR_PAIR(1));
	box(create, '|', '=');
	NcursesCenter(create, 0, "Add New Database");

	DatabaseList(conn, body);
	PREFRESH;
	refresh();
}
IntervalVector SetIntervalReg::findNodeBox(SetNodeReg * node) {
	IntervalVector bbox(bounding_box);
	IntervalVector box(bounding_box);
	node->findBox(bbox,&box);
	return box;
}
ENTRYPOINT void
draw_sws (ModeInfo *mi)
{
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
/*  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);*/
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int i;

  if (!sc->glx_context)
    return;

#if 0
  if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput))
    XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput);
#endif

  glDrawBuffer (GL_BACK);
  glXMakeCurrent (dpy, window, *(sc->glx_context));

  glClear (GL_COLOR_BUFFER_BIT);

  draw_stars (mi);

  glMatrixMode (GL_MODELVIEW);
  glPushMatrix ();

  if (debug_p)
    {
      int i;
      glPushMatrix ();
      if (textures_p) glDisable (GL_TEXTURE_2D);
      glLineWidth (1);
      glColor3f (0.4, 0.4, 0.4);
      glTranslatef (0,-1, 0);
      for (i = 0; i < 16; i++)
        {
          box (1, 1, 1);
          grid (1, 1, sc->char_width * sc->font_scale, sc->line_height, 0);
          glTranslatef(0, 1, 0);
        }
      if (textures_p) glEnable (GL_TEXTURE_2D);
      glPopMatrix ();
    }

  /* Scroll to current position */
  glTranslatef (0.0, sc->intra_line_scroll, 0.0);

  glColor3f (1.0, 1.0, 0.4);
  glCallList (sc->text_list);
  mi->polygon_count = sc->polygon_count;

  sc->intra_line_scroll += sc->line_height / scroll_steps;

  if (sc->intra_line_scroll >= sc->line_height)
    {
      sc->intra_line_scroll = 0;

      /* Drop the oldest line off the end. */
      if (sc->lines[0])
        free (sc->lines[0]);

      /* Scroll the contents of the lines array toward 0. */
      if (sc->total_lines > 0)
        {
          for (i = 1; i < sc->total_lines; i++)
            sc->lines[i-1] = sc->lines[i];
          sc->lines[--sc->total_lines] = 0;
        }

      /* Bring in new lines at the end. */
      get_more_lines (sc);

      if (sc->total_lines < max_lines)
        /* Oops, we ran out of text... well, insert some blank lines
           here so that new text still pulls in from the bottom of
           the screen, isntead of just appearing. */
        sc->total_lines = max_lines;

      glDeleteLists (sc->text_list, 1);
      sc->text_list = glGenLists (1);
      glNewList (sc->text_list, GL_COMPILE);
      sc->polygon_count = 0;
      glPushMatrix ();
      glScalef (sc->font_scale, sc->font_scale, sc->font_scale);
      for (i = 0; i < sc->total_lines; i++)
        {
          double fade = (fade_p ? 1.0 * i / sc->total_lines : 1.0);
          int offscreen_lines = 2;

          double x = -0.5;
          double y =  ((sc->total_lines - (i + offscreen_lines) - 1)
                       * sc->line_height);
          double xoff = 0;
          char *line = sc->lines[i];

          if (debug_p)
            {
              double xx = x * 1.4;  /* a little more to the left */
              char n[20];
              sprintf(n, "%d:", i);
              draw_string (sc, xx / sc->font_scale, y / sc->font_scale, n);
            }

          if (!line || !*line)
            continue;

          if (sc->line_thickness != 1 && !textures_p)
            {
              int max_thick_lines = MAX_THICK_LINES;
              GLfloat thinnest_line = 1.0;
              GLfloat thickest_line = sc->line_thickness;
              GLfloat range = thickest_line - thinnest_line;
              GLfloat thickness;

              int j = sc->total_lines - i - 1;

              if (j > max_thick_lines)
                thickness = thinnest_line;
              else
                thickness = (thinnest_line +
                             (range * ((max_thick_lines - j) /
                                       (GLfloat) max_thick_lines)));

              glLineWidth (thickness);
            }

          if (alignment >= 0)
            {
              int n = string_width (sc, line);
              xoff = 1.0 - (n * sc->font_scale);
            }

          if (alignment == 0)
            xoff /= 2;

          glColor3f (fade, fade, 0.5 * fade);
          draw_string (sc, (x + xoff) / sc->font_scale, y / sc->font_scale,
                       line);
          if (textures_p)
            sc->polygon_count += strlen (line);
        }
      glPopMatrix ();
      glEndList ();
    }

  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();
  glXSwapBuffers(dpy, window);

  sc->star_theta += star_spin;
}
void update_cd()
{
    FILE *tracks_fp;
    char track_name[MAX_STRING];
    int len;
    int track = 1;
    int screen_line = 1;
    WINDOW *box_window_ptr;
    WINDOW *sub_window_ptr;

    clear_all_screen();
    mvprintw(PROMPT_LINE, 0, "Re-entering tracks for CD.");
    if (!get_confirm()) {
        return;
    }
    move(PROMPT_LINE, 0);
    clrtoeol();

    remove_tracks();

    mvprintw(MESSAGE_LINE, 0, "Enter a blank line to finish");

    tracks_fp = fopen(TRACKS_FILE, "a");

    /* Just to show how, enter the information in a scrolling, boxed,
       window. The trick is to set-up a sub-window, draw a box around the
       edge, then add a new, scrolling, sub-window just inside the boxed
       sub-window. */
    box_window_ptr = subwin(stdscr, BOXED_LINES + 2, BOXED_ROWS + 2,
                            BOX_LINE_POS - 1, BOX_ROW_POS - 1);

    if (!box_window_ptr) {
        return;
    }
    box(box_window_ptr, ACS_VLINE, ACS_HLINE);

    sub_window_ptr = subwin(stdscr, BOXED_LINES, BOXED_ROWS, BOX_LINE_POS, BOX_ROW_POS);
    if (!sub_window_ptr) {
        return;
    }
    scrollok(sub_window_ptr, TRUE);
    werase(sub_window_ptr);
    touchwin(stdscr);

    do {
        //todo mvprintw
        mvwprintw(sub_window_ptr, screen_line++, BOX_ROW_POS + 2, "Track %d: ", track);
        clrtoeol();
        refresh();
        wgetnstr(sub_window_ptr, track_name, MAX_STRING);
        len = strlen(track_name);
        if (len > 0 && track_name[len - 1 ] == '\n') {
            track_name[len - 1] = '\0';
        }
        if (*track_name) {
            fprintf(tracks_fp, "%s,%d,%s\n", current_cat, track, track_name);
        }

        track++;
        if (screen_line > BOXED_LINES - 1) {
            /*time to start scrolling*/
            scroll(sub_window_ptr);
            screen_line--;
        }
    } while (*track_name);
    delwin(sub_window_ptr);

    fclose(tracks_fp);
}
示例#7
0
void DoRayTest()
{
    Vector3 origin(0.0f, 0.0f, 0.0f);
    BoundingSphere sphere(origin, 10.0f);

    // Test 1: Ray hits a bounding sphere that the ray is inside of.
    {
        Ray ray(origin, Vector3(0.0f, 0.0f, 1.0f));

        if (!ray.hasIntersected(sphere))
            throw std::runtime_error("DoRayTest() : Test 1 failed");
    }

    // Test 2: Ray hits a bounding sphere.
    {
        Ray ray(Vector3(0.0f, 0.0f, 100.0f), Vector3(0.0f, 0.0f, -1.0f));

        if (!ray.hasIntersected(sphere))
            throw std::runtime_error("DoRayTest() : Test 2 failed");
    }

    // Test 3: Ray misses a bounding sphere.
    {
        Ray ray(Vector3(0.0f, 0.0f, 100.0f), Vector3(0.0f, 0.0f, 1.0f));

        if (ray.hasIntersected(sphere))
            throw std::runtime_error("DoRayTest() : Test 3 failed");
    }

    BoundingBox box(Vector3(-10.0f, -10.0f, -10.0f), Vector3(10.0f, 10.0f, 10.0f));

    // Test 4: Ray hits a bounding box that the ray is inside of.
    {
        Ray ray(origin, Vector3(0.0f, 0.0f, 1.0f));

        if (!ray.hasIntersected(box))
            throw std::runtime_error("DoRayTest() : Test 4 failed");
    }

    // Test 5: Ray hits a bounding box.
    {
        Ray ray(Vector3(0.0f, 0.0f, 100.0f), Vector3(0.0f, 0.0f, -1.0f));

        if (!ray.hasIntersected(box))
            throw std::runtime_error("DoRayTest() : Test 5 failed");
    }

    // Test 6: Ray misses a bounding box.
    {
        Ray ray(Vector3(0.0f, 0.0f, 100.0f), Vector3(0.0f, 0.0f, 1.0f));

        if (ray.hasIntersected(box))
            throw std::runtime_error("DoRayTest() : Test 6 failed");
    }

    Plane xzPlane(origin, Vector3(0.0f, 1.0f, 0.0f));

    // Test 7: Ray intersects a plane.
    {
        Ray ray(Vector3(0.0f, 10.0f, 0.0f), Vector3(0.0f, -1.0f, 0.0f));

        if (!ray.hasIntersected(xzPlane))
            throw std::runtime_error("DoRayTest() : Test 7 failed");
    }

    // Test 8: Ray misses a plane.
    {
        Ray ray(Vector3(0.0f, 10.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f));

        if (ray.hasIntersected(xzPlane))
            throw std::runtime_error("DoRayTest() : Test 8 failed");
    }

    // Test 9: Line segment intersects a plane.
    {
        Vector3 pt1(0.0f, -10.0f, 0.0f);
        Vector3 pt2(0.0f, 10.0f, 0.0f);
        Ray ray(pt1, pt2 - pt1);

        if (!ray.hasIntersected(xzPlane))
            throw std::runtime_error("DoRayTest() : Test 9 failed");
    }

    // Test 10: Line segment misses a plane.
    {
        Vector3 pt1(0.0f, 10.0f, 0.0f);
        Vector3 pt2(0.0f, 20.0f, 0.0f);
        Ray ray(pt1, pt2 - pt1);

        if (ray.hasIntersected(xzPlane))
            throw std::runtime_error("DoRayTest() : Test 10 failed");
    }
}
示例#8
0
tree
box_rep::get_leaf_tree () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("no tree attached to this box");
  return "";
}
示例#9
0
box
box_rep::get_leaf_box () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("no box attached to this box");
  return box ();
}
示例#10
0
pencil
box_rep::get_leaf_pencil () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("this box is not textual");
  return pencil (false);
}
示例#11
0
language
box_rep::get_leaf_language () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("this box is not textual");
  return language ();
}
示例#12
0
font
box_rep::get_leaf_font () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("this box is not textual");
  return font ();
}
示例#13
0
string
box_rep::get_leaf_string () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("this box is not textual");
  return "";
}
示例#14
0
int
box_rep::get_leaf_right_pos () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("this box is not textual");
  return 0;
}
示例#15
0
void IPImageViewer::updateImage()
{
    if(_processStep && _processStep->process() && _processStep->process()->isResultReady())
    {
        // delete last image
        delete _image;
        _image = NULL;

        _rawData = NULL;
        _rawImage = NULL;

        // convert from IPLImage
        _rawData = _processStep->process()->getResultData(_resultIndex);

        // if the result is invalid, abort
        if(!_rawData)
        {
            setVisible(false);
            _imageViewerWindow->updateHistogram(NULL);
            _imageViewerWindow->updateStatistics(NULL);
            _imageViewerWindow->updateZoomwidget(NULL);
            return;
        }
        else
        {
            setVisible(true);
        }

        if(_rawData->type() == IPL_IMAGE_COLOR
                || _rawData->type() == IPL_IMAGE_GRAYSCALE
                || _rawData->type() == IPL_IMAGE_BW
                || _rawData->type() == IPL_IMAGE_ORIENTED
                )
        {
            _rawImage = _rawData->toImage();

            // show normal image
            _image = new QImage(_rawImage->rgb32(), _rawImage->width(), _rawImage->height(), QImage::Format_RGB32);
        }
        else if(_rawData->type() == IPL_IMAGE_COMPLEX)
        {
            _rawComplexImage = _rawData->toComplexImage();

            // show complex image
            _image = new QImage(_rawComplexImage->rgb32(), _rawComplexImage->width(), _rawComplexImage->height(), QImage::Format_RGB32);
        }
        else if(_rawData->type() == IPL_POINT)
        {
            // show point
            _rawData = _processStep->process()->getResultData(0);
            _image = new QImage(_rawData->toImage()->rgb32(), _rawData->toImage()->width(), _rawData->toImage()->height(), QImage::Format_RGB32);

            QPainter painter(_image);
            painter.setRenderHint(QPainter::Antialiasing, true);

            IPLPoint* p = _processStep->process()->getResultData(1)->toPoint();

            QPoint point;
            point.setX(p->x());
            point.setY(p->y());

            QBrush brush(Qt::red);
            painter.setBrush(brush);
            painter.drawEllipse(point, 10, 10);
        }
        else if(_rawData->type() == IPL_MATRIX)
        {
            int cellSize = 30;
            int headerSize = 30;

            IPLMatrix* matrix = _rawData->toMatrix();
            _image = new QImage(matrix->width()*cellSize+2*headerSize, matrix->height()*cellSize+2*headerSize, QImage::Format_RGB32);
            _image->fill(Qt::white);

            QPainter painter(_image);
            painter.setRenderHint(QPainter::Antialiasing, true);

            // header
            QPen pen(Qt::black);
            pen.setWidth(2);
            painter.setPen(pen);

            QString title("%1×%2 Matrix");
            painter.drawText(headerSize+2, headerSize-5, title.arg(matrix->width()).arg(matrix->height()));

            // content
            for(int y=0; y < matrix->height(); y++)
            {
                for(int x=0; x < matrix->width(); x++)
                {
                    QRectF box(x*cellSize+headerSize, y*cellSize+headerSize, cellSize, cellSize);
                    painter.drawText(box, Qt::AlignCenter|Qt::AlignVCenter, QString::number(matrix->get(x,y), 'f', 2));
                    painter.drawRect(box);
                }
            }
        }

        // update histogram
        _imageViewerWindow->updateHistogram(_rawImage);

        // update statistics
        _imageViewerWindow->updateStatistics(_rawImage);

        // update zoom widget
        _imageViewerWindow->updateZoomwidget(_rawImage);


        if(_image)
        {
            // we make a copy of the image data in order to prevent read access violations
            QPixmap pixmap = QPixmap::fromImage(_image->copy());

            _pixmapItem->setPixmap(pixmap);

            // center to 0,0
//            _pixmapItem->setPos(-_pixmapItem->boundingRect().width()/2, -_pixmapItem->boundingRect().height()/2);

            _graphicsScene->setSceneRect(_pixmapItem->boundingRect());
        }
        else
        {
            _pixmapItem->hide();
        }
        //_graphicsScene->update();

        // update title
        /*if(_tabIndex > -1)
        {
            IPLProcessPropertyString* property = (IPLProcessPropertyString*) _processStep->process()->property("title");
            QString title = QString::fromStdString(property->value());
            ((QTabWidget*) parent())->setTabText(_tabIndex, title);
        }*/
    }
    else
    {
        _imageViewerWindow->updateHistogram(NULL);
        _imageViewerWindow->updateStatistics(NULL);
        _imageViewerWindow->updateZoomwidget(NULL);
        setVisible(false);
    }
}
示例#16
0
lazy
box_rep::get_leaf_lazy () {
  failed_error << "The box is " << box (this) << "\n";
  FAILED ("no lazy attached to this box");
  return lazy ();
}
void GuiRectHandles::onMouseDragged(const GuiEvent &event)
{
   if(mHitHandle == 0)
      return;

   // The handles range from 0-1, so scale to fit within the
   // control's bounds.
   const Point2I& extent = getExtent();

   Point2I localMousePoint = globalToLocalCoord(event.mousePoint);

   Point2I diffI = localMousePoint - mHitPoint;
   Point2F diffF(diffI.x/F32(extent.x), diffI.y/F32(extent.y));

   RectF box(mHandleRect);
   bool postMoveExtentX = false;
   bool postMoveExtentY = false;
   bool keepExtent = false;

   switch(mHitHandle)
   {
      case 1:
      {
         // Top left
         box.point += diffF;
         postMoveExtentX = true;
         postMoveExtentY = true;
         break;
      }

      case 2:
      {
         // Top middle
         box.point.y += diffF.y;
         postMoveExtentY = true;
         break;
      }

      case 3:
      {
         // Top right
         box.point.y += diffF.y;
         box.extent.x += diffF.x;
         postMoveExtentY = true;
         break;
      }

      case 4:
      {
         // Middle right
         box.extent.x += diffF.x;
         break;
      }

      case 5:
      {
         // Bottom right
         box.extent += diffF;
         break;
      }

      case 6:
      {
         // Bottom middle
         box.extent.y += diffF.y;
         break;
      }

      case 7:
      {
         // Bottom left
         box.point.x += diffF.x;
         box.extent.y += diffF.y;
         postMoveExtentX = true;
         break;
      }

      case 8:
      {
         // Middle left
         box.point.x += diffF.x;
         postMoveExtentX = true;
         break;
      }

      case 9:
      {
         // Centre
         box.point += diffF;
         keepExtent = true;
         break;
      }

      default:
         break;
   }

   // Position limits
   if(box.point.x < 0.0f)
      box.point.x = 0.0f;
   else if(box.point.x > 1.0f)
      box.point.x = 1.0f;

   if(box.point.y < 0.0f)
      box.point.y = 0.0f;
   else if(box.point.y > 1.0f)
      box.point.y = 1.0f;

   // Move any extent to counter a change in handle position.  Do this
   // after the limits above to make sure the extent doesn't accidentally
   // grow when the position is clamped.
   if(postMoveExtentX)
      box.extent.x += mHandleRect.point.x - box.point.x;
   if(postMoveExtentY)
      box.extent.y += mHandleRect.point.y - box.point.y;

   // Extent limits
   if(box.extent.x < 0.0f)
      box.extent.x = 0.0f;
   else if(box.extent.x > 1.0f)
      box.extent.x = 1.0f;
   if(box.point.x+box.extent.x > 1.0f)
   {
      if(keepExtent)
         box.point.x = 1.0f-box.extent.x;
      else
         box.extent.x = 1.0f-box.point.x;
   }

   if(box.extent.y < 0.0f)
      box.extent.y = 0.0f;
   else if(box.extent.y > 1.0f)
      box.extent.y = 1.0f;
   if(box.point.y+box.extent.y > 1.0f)
   {
      if(keepExtent)
         box.point.y = 1.0f-box.extent.y;
      else
         box.extent.y = 1.0f-box.point.y;
   }

   mHandleRect = box;
   mHitPoint = localMousePoint;

   onHandleRectChange_callback();
}
示例#18
0
	RectBox(int x,int y,int w,int h,const char*l=0) : Fl_Box(x,y,w,h,l){
		box(FL_NO_BOX);
	}
示例#19
0
void taylortrack::vis::OutputVisualizer::update_main_window() {
  // Create Box around main window
  box(this->main_window_, 0, 0);

  wmove(this->main_window_, 1, 1);
  if (this->data_set_) {
    double x_axis_size = diagram_data_.size();
    int height, width;
    getmaxyx(this->main_window_, height, width);

    // Not the entire window usable
    width -= 2;
    height -= 4;

    // Calculate values per character
    int vpc = static_cast<int>(ceil(x_axis_size / static_cast<double>(width)));
    int actual_size = static_cast<int>(x_axis_size / vpc);

    // Calculate max value
    double max_value = 0.0f;
    for (int i = 0; i < actual_size; ++i) {
      double current_value = 0;
      for (int j = 0; j < vpc; ++j) {
        current_value += diagram_data_[i * vpc + j];
      }
      if (current_value > max_value) {
        max_value = current_value;
      }
    }

    wprintw(this->main_window_,
            "Debug-Values: %d %d %d %d %f",
            vpc,
            actual_size,
            COLORS,
            can_change_color(),
            max_value);

    if (max_value > 0.0) {
      // calculate the value of one square in the terminal
      double delta = max_value / height;

      // Add the vpc next values together and draw block if value high enough
      for (int y = 0; y < height; ++y) {
        for (int x = 0; x < actual_size; ++x) {
          double current_value = 0;
          for (int j = 0; j < vpc; ++j) {
            current_value += diagram_data_[x * vpc + j];
          }

          if (current_value >= (height - y) * delta) {
            wmove(this->main_window_, 1 + y, 1 + x);

            if (x % 2 == 0) {
              waddch(this->main_window_, ' ' | COLOR_PAIR(3));
            } else {
              waddch(this->main_window_, ' ' | COLOR_PAIR(4));
            }
          }
        }
      }
    } else {
      height = getmaxy(this->main_window_);
      height -= 2;

      wmove(this->main_window_, height / 2, 1);
      print_center(this->main_window_, "Invalid Data!");
    }
  } else {
    int height;
    height = getmaxy(this->main_window_);
    height -= 2;

    wmove(this->main_window_, height / 2, 1);
    print_center(this->main_window_, "Waiting for Data...");
  }

  // flush display buffer and write to screen
  wrefresh(this->main_window_);
}
示例#20
0
文件: JACK_Module.C 项目: nico202/non
JACK_Module::JACK_Module ( bool log )
    : Module ( 25, 25, name() )
{
    _prefix = 0;

    _connection_handle_outputs[0][0] = 0;
    _connection_handle_outputs[0][1] = 0;
    _connection_handle_outputs[1][0] = 0;
    _connection_handle_outputs[1][1] = 0;


    align( FL_ALIGN_TOP | FL_ALIGN_INSIDE );

    if ( log )
    {
        /* FIXME: how do Controls find out that a connected value has changed? How does this work in ladspa? */
        {
            Port p( this, Port::INPUT, Port::CONTROL, "Inputs" );
            p.hints.type = Port::Hints::INTEGER;
            p.hints.minimum = 0;
            p.hints.maximum = 16;
            p.hints.ranged = true;
            p.hints.visible = false;

            p.connect_to( new float );
            p.control_value_no_callback( 0 );

            add_port( p );
        }

        {
            Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
            p.hints.type = Port::Hints::INTEGER;
            p.hints.minimum = 0;
            p.hints.maximum = 16;
            p.hints.ranged = true;
            p.hints.visible = false;

            p.connect_to( new float );
            p.control_value_no_callback( 0 );

            add_port( p );
        }

        color( FL_DARK1 );

        log_create();
    }


    { Fl_Scalepack *o = new Fl_Scalepack( x() +  Fl::box_dx(box()),
                                          y() + Fl::box_dy(box()),
                                          w() - Fl::box_dw(box()),
                                          h() - Fl::box_dh(box()) );
        o->type( Fl_Pack::VERTICAL );
        o->spacing(0);


        { Fl_Scalepack *o = new Fl_Scalepack( x() +  Fl::box_dx(box()),
                                              y() + Fl::box_dy(box()),
                                              w(),
                                              24 - Fl::box_dh(box()) );
            o->type( Fl_Pack::HORIZONTAL );

            o->spacing( 0 );


            { Fl_Box *o = input_connection_handle = new Fl_Box( x(), y(), 18, 18 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->hide();
                o->image( input_connector_image ? input_connector_image : input_connector_image = new Fl_PNG_Image( "input_connector", img_io_input_connector_10x10_png, img_io_input_connector_10x10_png_len ) );

            }

            { Fl_Box *o = new Fl_Box( x() + 10, y(), w() - 20, h() );
                Fl_Group::current()->resizable(o);
            }


            { Fl_Button *o = dec_button = new Fl_Button( 0, 0, 12, h(), "-" );
                o->callback( cb_button, this );
                o->labelsize(10);
                o->labelfont( FL_HELVETICA_BOLD );
                o->hide();
            }
            { Fl_Button *o = inc_button = new Fl_Button( 0,0, 12, h(), "+" );
                o->labelsize(10);
                o->labelfont( FL_HELVETICA_BOLD );
                o->callback( cb_button, this );
                o->hide();
            }

            { Fl_Box *o = output_connection_handle = new Fl_Box( x(), y(), 12, 12 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->image( output_connector_image ? output_connector_image : output_connector_image = new Fl_PNG_Image( "output_connector", img_io_output_connector_10x10_png, img_io_output_connector_10x10_png_len ) );
                o->hide();
            }

            { Fl_Box *o = output_connection2_handle = new Fl_Box( x(), y(), 12, 12 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->image( output_connector_image ? output_connector_image : output_connector_image = new Fl_PNG_Image( "output_connector", img_io_output_connector_10x10_png, img_io_output_connector_10x10_png_len ) );
                o->hide();
            }

            o->end();
        }

        {
            Fl_Browser *o = connection_display = new Fl_Browser( 0, 0, w(), h() );
            o->has_scrollbar(Fl_Browser_::VERTICAL);
            o->textsize( 10 );
            o->textcolor( FL_LIGHT3 );
            o->textfont( FL_COURIER );
            o->box( FL_FLAT_BOX );
            o->color( FL_DARK1 );
            // o->color( fl_color_add_alpha( fl_rgb_color( 10, 10, 10 ), 100 ));

            Fl_Group::current()->resizable(o);
        }
        o->end();
        resizable(o);
    }
    end();
}
示例#21
0
void SetIntervalReg::findNeighbor(SetNodeReg* node, vector<SetNodeReg*> * neigh, vector<IntervalVector> * neighbox) {
    IntervalVector box(findNodeBox(node));
	root->findNeighbor(bounding_box,box,neigh,neighbox);
}
示例#22
0
文件: view.cpp 项目: floe/surface-2.0
void display() {

	int curtime = glutGet( GLUT_ELAPSED_TIME );
	curframe++;

	if ((curtime - lasttime) >= 1000) {
		fps = (1000.0*(curframe-lastframe))/((double)(curtime-lasttime));
		lasttime  = curtime;
		lastframe = curframe;
		snprintf(buffer,sizeof(buffer),"FPS: %f",fps);
		printf("%s\n",buffer);
	}

	// clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// move to origin
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0,VIDEO_RES_Y,0);
	glScalef(1.0f, -1.0f, 1.0f);

	surface_get_image( s40, image );
	int bc = surface_get_blobs( s40, blobs );

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture);
	glTexImage2D(GL_TEXTURE_2D, 0, 1, VIDEO_RES_X, VIDEO_RES_Y, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);

	glBegin(GL_TRIANGLE_FAN);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glTexCoord2f(0, 0); glVertex3f(0,0,0);
	glTexCoord2f(1, 0); glVertex3f(VIDEO_RES_X,0,0);
	glTexCoord2f(1, 1); glVertex3f(VIDEO_RES_X,VIDEO_RES_Y,0);
	glTexCoord2f(0, 1); glVertex3f(0,VIDEO_RES_Y,0);
	glEnd();

	glDisable(GL_TEXTURE_2D);

	// green: tip
	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( blobs[i].pos_x/2, blobs[i].pos_y/2 );

	// red: centroid(?)
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( blobs[i].ctr_x/2, blobs[i].ctr_y/2 );

	// yellow: axis(?)
	/*glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	for (int i = 0; i < bc; i++) cross( (blobs[i].pos_x+blobs[i].axis_x)/2, (blobs[i].pos_y+blobs[i].axis_y)/2 );*/

	// blue: bbox
	glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
	for (int i = 0; i < bc; i++) box( blobs[i].bb_pos_x/2, blobs[i].bb_pos_y/2, (blobs[i].bb_pos_x+blobs[i].bb_size_x)/2, (blobs[i].bb_pos_y+blobs[i].bb_size_y)/2 );

	// white: id
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	char id_buf[64];
	for (int i = 0; i < bc; i++) {
		snprintf(id_buf,64,"%d",blobs[i].blob_id);
		output(blobs[i].ctr_x/2, blobs[i].ctr_y/2,id_buf);
	}

	output(20,20,buffer);
	// redraw
	glutSwapBuffers();
}
示例#23
0
文件: nvramcui.c 项目: 0ida/coreboot
int main()
{
	int ch, done;
	ITEM *cur;
	
	/* coreboot data structures */
	lib_get_sysinfo();

	struct cb_cmos_option_table *opttbl = get_system_option_table();

	if (opttbl == NULL) {
		printf("Could not find coreboot option table\n");
		halt();
	}

	/* display initialization */
	initscr();
	keypad(stdscr, TRUE);
	cbreak();
	noecho();
	start_color();
	leaveok(stdscr, TRUE);
	curs_set(1);

	erase();
	box(stdscr, 0, 0);
	mvaddstr(0, 2, "coreboot configuration utility");

	/* prep CMOS layout into libcurses data structures */
	
	/* determine number of options, and maximum option name length */
	int numopts=0;
	int maxlength=0;
	struct cb_cmos_entries *option = first_cmos_entry(opttbl);
	while (option) {
		if ((option->config != 'r') && (strcmp("check_sum", option->name) != 0)) {
			maxlength = max(maxlength, strlen(option->name));
			numopts++;
		}
		option = next_cmos_entry(option);
	}
	if (numopts == 0) {
		printf("NO CMOS OPTIONS FOUND. EXITING!!!");
		return 1;
	}
	FIELD **fields = malloc(sizeof(FIELD*)*(2*numopts+1));
	int i;

	/* walk over options, fetch details */
	option = first_cmos_entry(opttbl);
	for (i=0;i<numopts;i++) {
		while ((option->config == 'r') || (strcmp("check_sum", option->name) == 0)) {
			option = next_cmos_entry(option);
		}
		fields[2*i] = new_field(1, strlen(option->name), i*2, 1, 0, 0);
		set_field_buffer(fields[2*i], 0, option->name);
		field_opts_off(fields[2*i], O_ACTIVE);

		fields[2*i+1] = new_field(1, 40, i*2, maxlength+2, 0, 0);
		char *buf = NULL;
		int fail = get_option_as_string(use_nvram, opttbl, &buf, option->name);
		switch (option->config) {
		case 'h': {
			set_field_type(fields[2*i+1], TYPE_INTEGER, 0, 0, (1<<option->length)-1);
			field_opts_on(fields[2*i+1], O_BLANK);
			break;
			  }
		case 's': {
			set_max_field(fields[2*i+1], option->length/8);
			field_opts_off(fields[2*i+1], O_STATIC);
			break;
			  }
		case 'e': {
			int numvals = 0;
			struct cb_cmos_enums *cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);

			/* if invalid data in CMOS, set buf to first enum */
			if (fail && cmos_enum) {
				buf = cmos_enum->text;
			}

			while (cmos_enum) {
				numvals++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}

			char **values = malloc(sizeof(char*)*numvals + 1);
			int cnt = 0;

			cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);
			while (cmos_enum) {
				values[cnt] = cmos_enum->text;
				cnt++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}
			values[cnt] = NULL;
			field_opts_off(fields[2*i+1], O_EDIT);
			set_field_type(fields[2*i+1], TYPE_ENUM, values, 1, 1);
			free(values); // copied by set_field_type
			break;
			  }
		default:
			  break;
		}
		if (buf) set_field_buffer(fields[2*i+1], 0, buf);
#if HOSTED
// underline is non-trivial on VGA text
		set_field_back(fields[2*i+1], A_UNDERLINE);
#endif
		field_opts_off(fields[2*i+1], O_BLANK | O_AUTOSKIP | O_NULLOK);

		option = next_cmos_entry(option);
	}
	fields[2*numopts]=NULL;

	FORM *form = new_form(fields);
	int numlines = min(numopts*2, 16);
	WINDOW *w = newwin(numlines+2, 70, 2, 1);
	WINDOW *inner_w = newpad(numopts*2, 68);
	box(w, 0, 0);
	mvwaddstr(w, 0, 2, "Press F1 when done");
	set_form_win(form, w);
	set_form_sub(form, inner_w);
	post_form(form);

	done = 0;
	while(!done) {
		ch=getch();
		if (ch == ERR) continue;
		switch (ch) {
		case KEY_DOWN:
			form_driver(form, REQ_NEXT_FIELD);
			break;
		case KEY_UP:
			form_driver(form, REQ_PREV_FIELD);
			break;
		case KEY_LEFT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_PREV_CHOICE);
			} else {
				form_driver(form, REQ_LEFT_CHAR);
			}
			break;
		case KEY_RIGHT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_NEXT_CHOICE);
			} else {
				form_driver(form, REQ_RIGHT_CHAR);
			}
			break;
		case KEY_BACKSPACE:
		case '\b':
			form_driver(form, REQ_DEL_PREV);
			break;
		case KEY_DC:
			form_driver(form, REQ_DEL_CHAR);
			break;
		case KEY_F(1):
			done=1;
			break;
		default:
			form_driver(form, ch);
			break;
		}
		render_form(form);
	}

	for (i = 0; i < numopts; i++) {
		char *name = field_buffer(fields[2*i], 0);
		char *value = field_buffer(fields[2*i+1], 0);
		char *ptr;
		for (ptr = value + strlen (value) - 1;
		     ptr >= value && *ptr == ' '; ptr--);
		ptr[1] = '\0';
		set_option_from_string(use_nvram, opttbl, value, name);
	}

	unpost_form(form);
	free_form(form);
	touchwin(stdscr);
	refresh();

	endwin();
	/* TODO: reboot */
	halt();
}
示例#24
0
int main (void)
{
        char x, y, temp, q;
    ioinit(); //Setup IO pins and defaults
        //USART_Init( MYUBRR);
        set_baud(6);//115200
        rprintf_devopen(put_char); /* init rrprintf */
        
        //check for existing preset values==============================================================
        temp = EEPROM_read((unsigned int)BPS);
        
        if ((temp < 1) | (temp > 6))//BPS will only be 1-6
        {
                cli();//Disable Interrupts
                
                EEPROM_write((unsigned int) BPS, 6);
                EEPROM_write((unsigned int) BACKLIGHT, 100);
                EEPROM_write((unsigned int) SPLASH, 1);
                EEPROM_write((unsigned int) REV, 0);
                
                sei();//Enable Interrupts
                
                BL_dutycycle = 100;
                baud_rate = 6;
                splash_screen = 1;
                reverse = 0;
        }
        
        else
        {
                baud_rate = temp;
                BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
                splash_screen = EEPROM_read((unsigned int)SPLASH);
                reverse = EEPROM_read((unsigned int)REV);
        }
        
        
        //Reset the display
        PORTC &= ~(1 << RESET);
        delay_ms(50);
        PORTC |= (1 << RESET);
        //delay_ms(500);

        
        clear_screen();

        set_page(0);
        
        set_x(0);
        
        display_on();
        
        //set display start line to 0
        //set control lines
        PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
        
        set_data(0xC0);
        //set_data(0xFF);
        delay();
        PORTC |= (1 << EN);//up
        delay();
        PORTC &= ~(1 << EN);//down
        delay();
        PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
        
        delay();
        
        x_offset = 0;

        set_page(0);
        
        DDRB |= (1<<BL_EN);//set PB2 as output
        
        set_backlight(BL_dutycycle);
        
        //Logo==========================================================
        if (splash_screen == 1)
        {
                y = 40;
                
                for (q = 0; q < 30; q++)
                {
                        temp = logo[q];
                        for (x = 56; x < 64; x++)
                        {
                                if (temp & 0x80) pixel(1,x,y);
                                
                                temp <<= 1;
                        }
                        
                        q++;
                        
                        temp = logo[q];
                        for (x = 64; x < 72; x++)
                        {
                                if (temp & 0x80) pixel(1,x,y);
                                
                                temp <<= 1;
                        }
                        y--;
        
                }        
        }
        
        pixel(0,0,0);//cheat
        
        RX_in = 0;
        
        delay_ms(1000);
        clear_screen();
        
        if (RX_in > 0)//revert to 115200
        {
                print_char(1,'1');
                print_char(1,'1');
                print_char(1,'5');
                print_char(1,'2');
                print_char(1,'0');
                print_char(1,'0');
                
                baud_rate = 6;
                set_baud(6);//115200
                
                cli();
                
                EEPROM_write((unsigned int) BPS, 6);
                
                sei();//Enable Interrupts
        }
        
        else (set_baud(baud_rate));
        
        delay_ms(1000);
        clear_screen();
        
        //main loop===================================================
        while(1)
        {
                if(RX_in != RX_read)
                {
                        x = RX_array[RX_read];
                        RX_read++;
                        if(RX_read >= 416) RX_read = 0;
                        
                        //Backspace===================================================
                        if(x == 8) del_char(0);
                        
                        //Special commands
                        else if (x == 124)
                        {        
                                //make sure the next byte is there
                                while(RX_in == RX_read);
                                
                                //0, clear screen======================================================
                                if(RX_array[RX_read] == 0)//^@
                                {
                                        clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                }
                                
                                //demo mode
                                else if(RX_array[RX_read] == 4)//^d
                                {
                                        RX_in = 0, RX_read = 0;
                                        demo();
                                        clear_screen();
                                        RX_in = 0;
                                }
                                
                                
                                //reverse mode
                                else if(RX_array[RX_read] == 18)//^r
                                {
                                        reverse ^= 1;
                                        clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                        
                                        cli();
                                        EEPROM_write((unsigned int) REV, reverse);
                                        sei();
                                }
                                
                                
                                //toggle spasl screen
                                else if(RX_array[RX_read] == 19)//^s
                                {
                                        splash_screen ^= 1;
                                        //clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                        
                                        cli();
                                        EEPROM_write((unsigned int) SPLASH, splash_screen);
                                        sei();
                                }
                                
                                else
                                {
                                        //set backlight (0 to 100)=========================================================
                                        if(RX_array[RX_read] == 2)//^b
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                BL_dutycycle = RX_array[RX_read];
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                                set_backlight(BL_dutycycle);
                                                
                                                cli();
                                                EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
                                                sei();
                                                
                                                

                                        }
                                        
                                        
                                        //change baud rate=========================================================
                                        if(RX_array[RX_read] == 7)//^g
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                //if (RX_array[RX_read] == '1') USART_Init( 1000000/2400-1);//4800
                                                //else if (RX_array[RX_read] == '2') USART_Init( 1000000/4800-1);//9600
                                                //else if (RX_array[RX_read] == '3') USART_Init( 1000000/9600-1);//19200
                                                //else if (RX_array[RX_read] == '4') USART_Init( 1000000/19200-1);//38400
                                                //else if (RX_array[RX_read] == '5') USART_Init( 1000000/28800-1);//57600
                                                //else if (RX_array[RX_read] == '6') USART_Init( 1000000/57600-1);//115200
                                                
                                                if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
                                                
                                                set_baud(baud_rate);
                                                
                                                cli();
                                                EEPROM_write((unsigned int) BPS, baud_rate);
                                                sei();
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                        }        
                                        
                                        
                                        //set x or y=========================================================
                                        if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))//^x or ^y
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
                                                else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                                if (x_offset > 159) x_offset = 159;
                                                if (y_offset > 127) y_offset = 127;

                                        }

                                        //set pixel=========================================================
                                        if (RX_array[RX_read] == 16)//^p
                                        {
                                                //need 3 bytes
                                                for (y = 0; y < 3; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;

                                        }

                                        
                                        //<ctrl>c, circle======================================================
                                        if(RX_array[RX_read] == 3)//^c
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                        //<ctrl>e, erase block======================================================
                                        if(RX_array[RX_read] == 5)//^e
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                        //box======================================================
                                        if(RX_array[RX_read] == 15)//^o
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }


                                        //line========================================================
                                        else if (RX_array[RX_read] == 12)//^l
                                        {
                                                //need 5 bytes
                                                for (y = 0; y < 5; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                }
        
                        }
                        
                        //print character to the screen===============================================
                        else
                        {
                                del_char(1);
                                print_char(1, x);
                        }
                }
                
        }
        
        //demo();
        


    
}
示例#25
0
void Plantinfo::update()
{

  werase(mWindow);
  box( mWindow, 0, 0 );
  wattron( mWindow, COLOR_PAIR( DEFAULT_COLOR ) );


  if( getAttr(plant) )
  {

    int i = 3;
    if( !getAttr( autoEnd ) )
    {
      mvwprintw( mWindow, 1, 2, "Plant Info" );


      INFO_PRINT( Health, health );
      INFO_PRINT( Root Level, rootLevel );
      INFO_PRINT( Leaf Level, leafLevel );
      INFO_PRINT( Flower Level, flowerLevel );
      INFO_PRINT( Root LvlUp, rootLevelUp );
      INFO_PRINT( Leaf LvlUp, leafLevelUp );
      INFO_PRINT( Flower LvlUp, flowerLevelUp );
    } else {

      std::system( "curl -s 131.151.189.189/api/top > topSeeds " );
      std::ifstream in( "topSeeds", ios::in );
      std::string seed, seeds[3];

      in >> seed;

      int k = 0;
      int start = 0;
      for( int i = 0; i < seed.length(); i++ )
      {
        if( seed[i] == ',' || i == seed.length()-1 )
        {
          seeds[k++] = seed.substr( start, i-start );
          start = i+1;
          if( k == 3 )
            break;
        }
      }

      seeds[2] += seed[seed.length()-1];

      mvwprintw( mWindow, 1, 2, "Top Seeds (pun lol)" );
      mvwprintw( mWindow, i++, 2, "1) %s", seeds[0].c_str() );
      mvwprintw( mWindow, i++, 2, "2) %s", seeds[1].c_str() );
      mvwprintw( mWindow, i++, 2, "3) %s", seeds[2].c_str() );


    }
    // Check if plant is talking
    GameState state = *getAttr( state );
    ++i;
    for( std::vector<Animation *>::iterator j = state.animations.begin(); j != state.animations.end(); j++ )
    {
      if( (*j)->type == TALK )
      {
        if( getAttr( plant )->objectID == ((Talk *)(*j))->plantID )
        {

          char *msg = ((Talk *)(*j))->message;
          bool nLine = false;


          for( int l = 0; l < 28; l++ )
          {
            if( msg[l] == '\n' )
            {
              nLine = true;
            }
          }

          while( strlen( msg ) > 28 || nLine )
          {
            nLine = false;
            char str[29];
            strncpy( str, msg, 28 );
            int n = 28;

            for( int l = 0; l < 28 && l < strlen(msg); l++ )
            {
              if( str[l] == '\n' )
              {

                str[l] = '\0';
                n = l;
                break;
              }

            }
            str[28] = '\0';
            mvwprintw( mWindow, i++, 2, "%s", str );
            msg += n+1;

            for( int l = 0; l < 28; l++ )
            {
              if( msg[l] == '\n' )
              {
                nLine = true;
                break;
              }
            }

          }
          mvwprintw( mWindow, i++, 2, "%s", msg );
        }
      }
    }


  } else {
    if( !getAttr( autoEnd ) )
示例#26
0
void
update_history_win(WINDOW *win)
{
	int i;
	int col = COLS-2;
	int sig, rat;

	if (col > MAX_HISTORY)
		col = 4 + MAX_HISTORY;

	werase(win);
	wattron(win, WHITE);
	box(win, 0 , 0);
	print_centered(win, 0, COLS, " Signal/Rate History ");
	mvwhline(win, SIGN_POS, 1, ACS_HLINE, col);
	mvwhline(win, SIGN_POS+2, 1, ACS_HLINE, col);
	mvwvline(win, 1, 4, ACS_VLINE, LINES-3);

	wattron(win, GREEN);
	mvwprintw(win, 2, 1, "dBm");
	mvwprintw(win, normalize_db(30, SIGN_POS - 1) + 1, 1, "-30");
	mvwprintw(win, normalize_db(40, SIGN_POS - 1) + 1, 1, "-40");
	mvwprintw(win, normalize_db(50, SIGN_POS - 1) + 1, 1, "-50");
	mvwprintw(win, normalize_db(60, SIGN_POS - 1) + 1, 1, "-60");
	mvwprintw(win, normalize_db(70, SIGN_POS - 1) + 1, 1, "-70");
	mvwprintw(win, normalize_db(80, SIGN_POS - 1) + 1, 1, "-80");
	mvwprintw(win, normalize_db(90, SIGN_POS - 1) + 1, 1, "-90");
	mvwprintw(win, SIGN_POS-1, 1, "-99");

	mvwprintw(win, 1, col-6, "Signal");

	wattron(win, CYAN);
	mvwprintw(win, TYPE_POS, 1, "TYP");
	mvwprintw(win, 2, col-11, "Packet Type");

	wattron(win, A_BOLD);
	wattron(win, BLUE);
	mvwprintw(win, 3, col-4, "Rate");
	mvwprintw(win, RATE_POS-12, 1, "300");
	mvwprintw(win, RATE_POS-11, 1, "275");
	mvwprintw(win, RATE_POS-10, 1, "250");
	mvwprintw(win, RATE_POS-9, 1, "225");
	mvwprintw(win, RATE_POS-8, 1, "200");
	mvwprintw(win, RATE_POS-7, 1, "175");
	mvwprintw(win, RATE_POS-6, 1, "150");
	mvwprintw(win, RATE_POS-5, 1, "125");
	mvwprintw(win, RATE_POS-4, 1, "100");
	mvwprintw(win, RATE_POS-3, 1, " 75");
	mvwprintw(win, RATE_POS-2, 1, " 50");
	mvwprintw(win, RATE_POS-1, 1, " 25");
	wattroff(win, A_BOLD);

	i = hist.index - 1;

	while (col > 4 && hist.signal[i] != 0)
	{
		sig = normalize_db(-hist.signal[i], SIGN_POS - 1);

		wattron(win, ALLGREEN);
		mvwvline(win, sig + 1, col, ACS_BLOCK, SIGN_POS - sig - 1);

		wattron(win, get_packet_type_color(hist.type[i]));
		mvwprintw(win, TYPE_POS, col, "%c", \
			get_packet_type_char(hist.type[i]));

		if (hist.retry[i])
			mvwprintw(win, TYPE_POS+1, col, "r");

		rat = hist.rate[i]/250;

		wattron(win, A_BOLD);
		wattron(win, BLUE);
		mvwvline(win, RATE_POS - rat, col, 'x', rat);
		wattroff(win, A_BOLD);

		i--;
		col--;
		if (i < 0)
			i = MAX_HISTORY-1;
	}
	wnoutrefresh(win);
}
示例#27
0
void GLC_OctreeNode::addChildren()
{
    Q_ASSERT(m_Children.isEmpty());
    Q_ASSERT(!m_BoundingBox.isEmpty());

    const double xLower=  m_BoundingBox.lowerCorner().x();
    const double yLower=  m_BoundingBox.lowerCorner().y();
    const double zLower=  m_BoundingBox.lowerCorner().z();

    const double xUpper=  m_BoundingBox.upperCorner().x();
    const double dX= (xUpper - xLower) / 2.0;
    const double yUpper=  m_BoundingBox.upperCorner().y();
    const double dY= (yUpper - yLower) / 2.0;
    const double zUpper=  m_BoundingBox.upperCorner().z();
    const double dZ= (zUpper - zLower) / 2.0;


    // Add 8 Children
    GLC_Point3d lower;
    GLC_Point3d upper;
    GLC_OctreeNode* pOctreeNode= NULL;

    {   // Child 1
        lower.setVect(xLower, yLower, zLower);
        upper.setVect(xLower + dX, yLower + dY, zLower + dZ);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 2
        lower.setVect(xLower + dX, yLower, zLower);
        upper.setVect(xUpper, yLower + dY, zLower + dZ);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 3
        lower.setVect(xLower + dX, yLower + dY, zLower);
        upper.setVect(xUpper, yUpper, zLower + dZ);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 4
        lower.setVect(xLower, yLower + dY, zLower);
        upper.setVect(xLower + dX, yUpper, zLower + dZ);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 5
        lower.setVect(xLower, yLower, zLower + dZ);
        upper.setVect(xLower + dX, yLower + dY, zUpper);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 6
        lower.setVect(xLower + dX, yLower, zLower + dZ);
        upper.setVect(xUpper, yLower + dY, zUpper);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 7
        lower.setVect(xLower + dX, yLower + dY, zLower + dZ);
        upper.setVect(xUpper, yUpper, zUpper);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
    {   // Child 8
        lower.setVect(xLower, yLower + dY, zLower + dZ);
        upper.setVect(xLower + dX, yUpper, zUpper);
        GLC_BoundingBox box(lower, upper);
        pOctreeNode= new GLC_OctreeNode(box, this);
        m_Children.append(pOctreeNode);
    }
}
示例#28
0
/*
 * Testing the perturbers
 */
int main(int argc, char** argv) {

    if (argc != 4)
        BNB_ERROR_REPORT("Usage: searchall.exe json_file log_for_incumbents log_for_allvalues\n");
    std::string jsons;
    FileUtils::getStringFromFile(argv[1], jsons);
    lur::MatModel mm;
    lur::ParseJson::parseModelData(jsons, mm);
    double x[mm.mNumLayers * 3];
    double y[mm.mNumLayers * 3];
    double ev;
    lur::ParseJson::parseLatticeData(jsons, mm, ev, x);

#if 0    
    // Lennard Jones
    lur::PotentialCutter pc(3 * 3, 3 * 3 - 2.8 * 2.8, lur::ljpotent);
    lur::PairPotentialEnergy enrg(mm, pc);
#endif
    
#if 0    
    // Morse
    lur::PairPotentialEnergy enrg(mm, morsepotent);
#endif
    
#if 1
    // Tersoff
    lur::TersoffParams tparam;
    lur::fillCarbonParametersTersoffOriginal(tparam);
    lur::TersoffUtils tutils(tparam);
    lur::TersoffEnergy enrg(mm, tutils);
#endif    

    const int N = mm.mNumLayers * 3;
    lur::LurieObj obj(enrg, mm);

    Box<double> box(N);
    lur::ParseJson::parseBoxData(jsons, box);

    BBStopper stp;
    BBBoxDescent<double> locs(box, &stp);
    locs.getOptions().mHInit = 4;
    locs.getOptions().mDec = 0.5;
    locs.getOptions().mHLB = 1e-6;
    locs.getOptions().mInc = 1.75;
    locs.setObjective(&obj);


    BoxconProblem<double> bp;
    bp.mBox = box;
    bp.mObj = &obj;
    LipBounder<double> lb(bp.mObj);
    const double lipconst = 128;
    lb.setLipConst(lipconst);
    BoxconBNB<double> bnb;
    bnb.addBounder(&lb);
    bnb.getOptions().mEps = 0.1;
    bnb.init(bp);

    double bestv = 0;
    int cnt = 0;
    time_t tstart = time(NULL);
    auto hndl = [&](BoxconBNB<double>::Solution& incum, BoxconBNB<double>::Sub & sub) {
        BoxUtils::getCenter(sub.mBox, y);
        double u = obj.func(y);
        //std::cout << "u = " << u << "\n";        
        // if ((u < 0.9 * incum.mValue) && ((cnt++ % 100) == 0)) {
        //if ((cnt++ % 100) == 0) {
        if (true) {
        //if (BoxUtils::radius(sub.mBox) < 2) {
            std::cout << "Search from " << u << "\n";
            std::cout << "In box " << BoxUtils::toString(sub.mBox) << "\n";
            std::cout << " with radius " << BoxUtils::radius(sub.mBox) << "\n";
            std::cout << " with lb " << sub.mBound << "\n";
            VecUtils::vecPrint(N, y);

            double v;
            locs.search(y, &v);

            auto logval = [&] (const char* fname, double v) {
                time_t tcur = time(NULL) - tstart;
                std::ostringstream os;
                os << tcur << " " << v << "\n";
                FileUtils::updateFileWithContent(fname, os.str().c_str());
            };

            std::cout << "Found v = " << v << "\n";
            logval(argv[3], v);
            VecUtils::vecPrint(N, y);

            if (v < bestv) {
                bestv = v;
                std::cout << "Improved incumbent " << bestv << " from " << u << "\n";
                incum.mValue = v;
                VecUtils::vecPrint(N, y);
                VecUtils::vecCopy(N, y, x);
                logval(argv[2], v);
                enrg.setFixedAtoms(true);
                double v;
                locs.search(y, &v);
                enrg.setFixedAtoms(false);
                std::cout << "Free configuration " << v << "\n";
                VecUtils::vecPrint(N, y);
            }
        }
    };

    bnb.setHandler(hndl);
    long long steps = 1000000;
    bnb.solve(steps);
    std::cout << steps << " performed\n";
#if 0
    std::cout << "The solution is " << bnb.getIncumbent().mValue << " found in " << steps << " steps \n";
    VecUtils::vecPrint(N, (double*) bnb.getIncumbent().mX);
    VecUtils::vecCopy(N, (double*) bnb.getIncumbent().mX, x);
#endif    



#if 0
    std::cout << "Searching in box " << BoxUtils::toString(box) << "\n";
    double v = mbhbc.search(x);
#endif

    enrg.setFixedAtoms(true);
    double v;
    locs.search(x, &v);


    std::cout << "Found v = " << v << "\n";
    VecUtils::vecPrint(N, x);
    std::string json;
    json += "{\n";
    lur::GenJSON::genModel(mm, json);
    json += ", \n";
    lur::GenJSON::genBox(box, json);
    json += ", \n";
    lur::GenJSON::genLattice(mm, v, x, json);
    json += "\n}\n";
    std::cout << json << "\n";
    return 0;
}
示例#29
0
文件: EXAMPLE.CPP 项目: ananay/turboc
void main(){
	_setcursortype(_NOCURSOR);
	randomize();

	clrscr();

	for(int o = 0; o<9; o++){
		gotoxy(3, 3+o);
		//puts(banner2[o]);
		cprintf("%s",banner2[o]);
		delay(50);
	}
	for(int p = 0; p<9; p++){
		gotoxy(20, 15+p);
		cprintf("%s",banner3[p]);
//		puts(banner3[p]);
		delay(50);
	}
	gotoxy(55, 25);
	cout<<"by Shreyas Kishore, XI-F";
	getch();
	clrscr();

	char ch;
	int  selprev;

	box(0,0,77,24,50);
	gotoxy(35,1);
	char name[] = "ЕFlappy BirdЦ";
	int n = 0;

	for(int l = 0; l<=7; l++){
		gotoxy(12,16 +l);
//		cprintf("%s",banner1[p]);
		puts(banner1[l]);
	}
	gotoxy(35,1);
	while(name[n] != '\0'){
		cout<<name[n];
		n++;
		delay(25);
	}
		box(30, 4, 17, 10, 30);
	gotoxy(35, 7);
	cout<<"Choose Mode:";
		gotoxy(35,10);
		cout<<"Normal Mode";
		gotoxy(35,13);
		cout<<"Disco Mode";

	while((int)ch != 13){

		if((int)ch == 72){selprev = selection; selection = 0;}
		if((int)ch == 80){selprev = selection; selection = 1;}
		if(selprev != selection){
			for(int i = 32; i<=48; i++){
				for( int j = 7; j<= 14; j++){
					gotoxy(i,j);
					cout<<" ";
				}
			}
		}
		if(selection == 0) box(32,8,13,2);
		if(selection == 1) box(32,11,13, 2);
		box(0,0,77,24,1000);
	gotoxy(35,1);
	cout<<"ЕFlappy BirdЦ";
		box(30, 4, 17, 10, 300);
	gotoxy(35, 7);
	cout<<"Choose Mode:";
		gotoxy(35,10);
		cout<<"Normal Mode";
		gotoxy(35,13);
		cout<<"Disco Mode";
		ch = getch();
	}


	//SetConsoleCursorInfo(_NOCURSOR);
	int x = 25, y = 2, xprev, yprev, con = 0, scorecalc = 0, phase= 0;
	float del = 200;
	makecyl();
	box();
	gotoxy(35,1);
	//name = "Flappy Bird";
	n = 0;
	while(name[n] != '\0'){
		cout<<name[n];
		n++;
		delay(25);
	}
	line(2, 24, 78, 24, 60, 3);
	long event_fall = timems(), press, event_makecyl = timems(), event_display = timems(), event_shift = timems();
    while(y<=24 && data[yprev][xprev]==0){
	gotoxy(x,y);
	//cout<<setclr(9);
	cout<<"";
	gotoxy(xprev, yprev);
	cout<<" ";

	   if(timemssince(event_display)>50){
		display();
		event_display = timems();
		linewphase(2, 24, 78, 24, 1000, phase);
	   }
	   if(timemssince(event_shift)>50){
		shift();
		scorecalc++;
		event_shift = timems();
		data_assign();
		phase++;
		score= (scorecalc-35)/30;
		if(score<0)score = 0;
	   }
	   if(timemssince(event_makecyl)>1500){
		makecyl();
		event_makecyl = timems();
	   }
	   if(timemssince(event_fall)>del){
		del-=30;
		xprev = x;
		yprev = y;
		y++;
		if(del<40) del = 40;
		event_fall = timems();
	   }
	   if(getchn()){
		if(con == 0){
		xprev = x;
		yprev = y;
		//if(y<2) y = 2;
		del = 200;
		con = 1;
		press = timems();
	   } }
	   if(con==1 && timemssince(press)>0 && timemssince(press)<=30){yprev=y; y--; con++;}
	   else if(con==2 && timemssince(press)>30 && timemssince(press)<=80){yprev=y;y--; con++;}
	   else if(con==3 && timemssince(press)>80 && timemssince(press)<=150){yprev=y;y--; con++;}
	   else if(con==4 && timemssince(press)>150 && timemssince(press)<=240){yprev=y;y--; con++;}
	   else if(con==5 && timemssince(press)>240 && timemssince(press)<=350){yprev=y;y--; con=0;}
	   if(y<2)y=2;
	}

	for(int xx=34; xx<=46; xx++){
		for(int yy = 11; yy<=15; yy++){
			gotoxy(xx,yy);
			cout<<" ";
		}
	}
	box(32, 9, 13, 6, 5, 4);
	gotoxy(36,12);
	cout<<"GAME OVER!";
	gotoxy(36,14);
	cout<<"Score: "<<score;
	getch();
}
示例#30
0
box
box_rep::transform (frame fr) {
  (void) fr;
  return box ();
}