Esempio n. 1
1
void UpdateController::moveSnake(Snake &snake) {
    switch (input) {
        case KEY_LEFT:
            snake.movex(-1);
            break;
        case KEY_RIGHT:
            snake.movex(1);
            break;
        case KEY_UP:
            snake.movey(-1);
            break;
        case KEY_DOWN:
            snake.movey(1);
            break;
        default:
            snake.movex(1);
    }
    for ( auto iter = coins.begin(), endPtr = coins.end() ; iter != endPtr ; ++iter ) {
		if (snake.headLiesOn(iter->getxy())) {
			snake.grow(iter->getvalue());
			coinMutex.lock();
			*iter = Coin(getFreeCoord());
			coinMutex.unlock();
			break;
		}
	}
    auto head = snake.getHead();
    if (snake.bitItself() || !map.contains(head) || snakeWallCollision()) {
        stop();
    }
}
Esempio n. 2
0
void net_motion_test::OnMouseMove(UINT nFlags, CPoint point)
{
	//TRACE("on mouse move\n");

	if(m_bmouse_down)
	{
		int orix,oriy;
		getxy(m_ori,&orix,&oriy);
		
		int dstx,dsty;
		getxy(point,&dstx,&dsty);
		
		int minx = min(orix,dstx);
		int maxx = max(orix,dstx);
		int miny = min(oriy,dsty);
		int maxy = max(oriy,dsty);
		
		for(int i = minx; i <= maxx; i++)
		{
			for(int j = miny; j <= maxy; j++)
			{
				if(m_ori_is_set)
				{
					set_motion(i,j);
				}else{
					clear_motion(i,j);
				}				
			}
		}
	}

	CEdit::OnMouseMove(nFlags,point);
}
Esempio n. 3
0
void drawfree(void)
{
	int i;
	setfillstyle(1,WHITE);
	for(i=Tail;i<50;i++)
		{
			bar(getxy(i).lx,getxy(i).ly,getxy(i).rx,getxy(i).ry);
		}
}
Esempio n. 4
0
void drawother(void)
{
	int id,i;
	for(id=Control.First+1;id<(Control.First+Control.ProcNum);id++)
	{
		setfillstyle(1,retcolor(Proc[id].Resource));
		for(i=Proc[id].StartP;i<Proc[id].StartP+Proc[id].Resource;i++)
			bar(getxy(i).lx,getxy(i).ly,getxy(i).rx,getxy(i).ry);
	}
}
Esempio n. 5
0
int		moy(t_bunny_pixelarray *pix, int i, int j, int v)
{
  t_color	*pixels;
  int		coef;
  int		som;

  pixels = pix->pixels;
  som = pixels[getxy(i, j, pix)].argb[v];
  coef = 1;
  if (i - 1 >= 0 && j - 1 >= 0 && ++coef)
    som += pixels[getxy(i - 1, j - 1, pix)].argb[v];
  if (i - 1 >= 0 && ++coef)
    som += pixels[getxy(i - 1, j, pix)].argb[v];
  if (i - 1 >= 0 && j + 1 < HB && ++coef)
    som += pixels[getxy(i - 1, j + 1, pix)].argb[v];
  if (j - 1 >= 0 && ++coef)
    som += pixels[getxy(i, j - 1, pix)].argb[v];
  if (j + 1 < HB && ++coef)
    som += pixels[getxy(i, j + 1, pix)].argb[v];
  if (i + 1 < WB && j - 1 >= 0 && ++coef)
    som += pixels[getxy(i + 1, j - 1, pix)].argb[v];
  if (i + 1 < WB && ++coef)
    som += pixels[getxy(i + 1, j, pix)].argb[v];
  if (i + 1 < WB && j + 1 < HB && ++coef)
    som += pixels[getxy(i + 1, j + 1, pix)].argb[v];
  return (som / coef);
}
Esempio n. 6
0
void display(void)
{

	int i;
	int id;
	for(id=Control.First;id<(Control.First+Control.ProcNum);id++)
	{
		setfillstyle(1,retcolor(Proc[id].Resource));
		for(i=Proc[id].StartP;i<Proc[id].StartP+Proc[id].Resource;i++)
			bar(getxy(i).lx,getxy(i).ly,getxy(i).rx,getxy(i).ry);
	}

	drawfree();
}
Esempio n. 7
0
void net_motion_test::set_motion(POINT pt)
{
	int x,y;
	getxy(pt,&x,&y);

	set_motion(x,y);
}
Esempio n. 8
0
static void get_sample (calibration *cal,
			int index, int x, int y, char *name)
{
	static int last_x = -1, last_y;

//	if (last_x != -1) {
//#define NR_STEPS 10
//		int dx = ((x - last_x) << 16) / NR_STEPS;
//		int dy = ((y - last_y) << 16) / NR_STEPS;
//		int i;
//		last_x <<= 16;
//		last_y <<= 16;
//		for (i = 0; i < NR_STEPS; i++) {
//			put_cross (last_x >> 16, last_y >> 16, 2 | XORMODE);
//			uDelay (1000);
//			put_cross (last_x >> 16, last_y >> 16, 2 | XORMODE);
//			last_x += dx;
//			last_y += dy;
//		}
//	}

	put_cross(x, y, 2 | XORMODE);
	getxy (&cal->x [index], &cal->y [index]);
	put_cross(x, y, 2 | XORMODE);
//	Delay (300);

	last_x = cal->xfb [index] = x;
	last_y = cal->yfb [index] = y;

	printf("%s : LCD X = %4d Y = %4d\n\r", name, cal->xfb [index], cal->yfb [index]);
	printf("%s : X = %4d Y = %4d\n\r", name, cal->x [index], cal->y [index]);
}
Esempio n. 9
0
void		blurp(t_bunny_pixelarray *pix, int intensit)
{
  t_color	*pixels;
  t_color	*cpy;
  int		i;
  int		j;

  pixels = pix->pixels;
  cpy = alloca(HB * WB * sizeof(t_color));
  while (intensit--)
    {
      i = -1;
      while (++i < WB)
	{
	  j = -1;
	  while (++j < HB)
	    cpy[getxy(i, j, pix)].full = RGBA_C(moy(pix, i, j, 0),
						moy(pix, i, j, 1),
						moy(pix, i, j, 2),
						moy(pix, i, j, 3));
	}
      i = -1;
      while (++i < WB * HB)
	pixels[i].full = cpy[i].full;
    }
}
Esempio n. 10
0
zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued)
{
  char c;
  int x,y;
  int i=0;
  int t=timeout*100;
  uint32 s,ms,tm;
  set_timeout(timeout);
  timer_ms_gettime(&s,&ms);

  i=strlen(buf);
  do {
    c=os_read_key(-1,1);
    if(c>=32 && c <= 176) c99_printf("%c",c);
    switch(c) {
    case 0:
    case 13:
      break;
    case 8:
      if(i>0) {
        i--;
        buf[i]='\0';
        getxy(&x,&y);
        locate(x-1,y);
      }
      break;
    default:
      buf[i]=c;
      i++;
      break;
    }
  } while (c!=13&&c!=0);
  buf[i]='\0';
  return c;
}
Esempio n. 11
0
/*******************************************************************************
*	Description		:
*	Argurments		:
*	Return value	:
*	Modify			:
*	warning			:
*******************************************************************************/
static void get_sample (struct tsdev *ts, calibration *cal, int index, int x, int y, char *name)
{
	static int last_x = -1, last_y;

	if (last_x != -1)
	{
		#define NR_STEPS 10
		
		int dx = ((x - last_x) << 16) / NR_STEPS;
		int dy = ((y - last_y) << 16) / NR_STEPS;
		int i;
		last_x <<= 16;
		last_y <<= 16;
		for (i = 0; i < NR_STEPS; i++)
		{
			usleep (1000);
			last_x += dx;
			last_y += dy;
		}
	}

	getxy (ts, &cal->x [index], &cal->y [index]);

	last_x = cal->xfb [index] = x;
	last_y = cal->yfb [index] = y;

	printf("%s : X = %4d Y = %4d\n", name, cal->x [index], cal->y [index]);
}
Esempio n. 12
0
BOOL net_motion_test::is_motion_set(POINT pt)
{
	int x,y;
	getxy(pt,&x,&y);

	return is_motion_set(x,y);
}
Esempio n. 13
0
  /* Move the cursor forward.  */
  void cl_forward (int count)
    {
      lpos += count;

      /* If the cursor goes outside, scroll the screen to the right.  */
      if (xpos + count >= CMDLINE_WIDTH)
	cl_refresh (1, 0);
      else
	{
	  xpos += count;

	  if (current_term->flags & TERM_DUMB)
	    {
	      int i;
	      
	      for (i = lpos - count; i < lpos; i++)
		{
		  if (! echo_char)
		    grub_putchar (buf[i]);
		  else
		    grub_putchar (echo_char);
		}
	    }
	  else
	    gotoxy (xpos, getxy () & 0xFF);
	}
    }
Esempio n. 14
0
unsigned short statInput(unsigned short l/*length of space to border*/)
{
	auto isNumber = true;
	auto isValidNumber = true;
	auto errorEncountered = false;
	std::string userInput;
	long long number;
	short x, y;
	getxy(x, y);
	do
	{
		isValidNumber = true;
		do
		{
			gotoxy(x, y);
			for(unsigned short i = 0; i < l; ++i)
			{
				std::cout << ' ';
			}
			gotoxy(x, y);
			isNumber = true;
			getline(std::cin, userInput);
			for(unsigned short i = 0; i < userInput.size() && isNumber == true; ++i)
			{
				if(isdigit(userInput[i]))
					isNumber = true;
				else
				{
					isNumber = false;
					errorEncountered = true;
					gotoxy(64, y);
					std::cout << "Please enter";
					gotoxy(64, y + 1);
					std::cout << "number 0-50,000";
				}
			}
		} while(isNumber == false);
		number = std::stoul(userInput);
		if(number > 50000)
		{
			isValidNumber = false;
			errorEncountered = true;
			gotoxy(64, y);
			std::cout << "Please enter";
			gotoxy(64, y + 1);
			std::cout << "number 0-50,000";
		}
	} while(isValidNumber == false);
	if(errorEncountered == true)
	{
		errorEncountered = false;
		gotoxy(64, y);
		std::cout << "            ";
		gotoxy(64, y + 1);
		std::cout << "               ";
	}
	return static_cast<unsigned short>(number);
}
Esempio n. 15
0
void tty_save_cursor (void)
{
#ifdef _WIN32
	getxy (&tty_saved_x, &tty_saved_y);
#else
	printf ("\x1b[s");
	fflush (stdout);
#endif
}
Esempio n. 16
0
File: pd_cal.c Progetto: miaofng/ulp
static void get_sample (pdl_cal_t *cal, int index, int x, int y, char *name)
{
	struct lcd_s *lcd = lcd_get(NULL);
	put_cross (lcd, x, y);
	getxy (&cal->x [index], &cal->y [index]);
	clr_cross(lcd, x, y);
	mdelay(1000);

	cal->xfb [index] = x;
	cal->yfb [index] = y;
	printf ("%s : (%4d,%4d)->(%4d,%4d)\n", name, x, y, cal->x [index], cal->y [index]);
}
Esempio n. 17
0
void tty_erase_eol (void)
{
#ifdef _WIN32
	unsigned	x, y;

	getxy (&x, &y);
	setregion (x, y, ' ', tty_attribs, tty_max_x - x + 1, 1);
#else
	printf ("\x1b[K");
	fflush (stdout);
#endif
}
Esempio n. 18
0
void tty_erase_line (void)
{
#ifdef _WIN32
	unsigned	x, y;

	getxy (&x, &y);
	setregion (tty_start_x, y, ' ', tty_attribs, tty_max_x - tty_start_x + 1, 1);
#else
	printf ("\x1b[2K");
	fflush (stdout);
#endif
}
Esempio n. 19
0
void drawrun(void)
{
	int i,k,size,id,timesub,color,j=0,a;
	char msg[50];
	struct time t,st;

	id=Control.First;
	Proc[id].RunTime=biuldtime();
	st=Proc[id].RunTime;
	size=Proc[Control.First].Resource;

	gettime(&t);
	timesub=(t.ti_hour*60*60*100+t.ti_min*60*100+t.ti_sec*100+t.ti_hund)
		-(st.ti_hour*60*60*100+st.ti_min*60*100+st.ti_sec*100+st.ti_hund);
	a=0;
	while(timesub<=5*Proc[id].SerTime)
	{
		color=5+j%10;
		j++;
		setfillstyle(6,color);
		for(i=0;i<size;i++)
		{
			bar(getxy(i).lx,getxy(i).ly,getxy(i).rx,getxy(i).ry);
		}
		gettime(&t);
		timesub=(t.ti_hour*60*60*100+t.ti_min*60*100+t.ti_sec*100+t.ti_hund)
		-(st.ti_hour*60*60*100+st.ti_min*60*100+st.ti_sec*100+st.ti_hund);

		setcolor(11);
		sprintf(msg,"The process %d is running... ...",(id+1));
		outtextxy(30,450,msg);

		setcolor(YELLOW);
		outtextxy(150,395,"Now you can ALSO press "
					"any key to produce processes... ...");
		setcolor(11);
		outtextxy(5,395,"* Time Show *");
		moveto(10+a,410);
		lineto(10+a,425);
		a++;
	}
	setfillstyle(1,WHITE);
	for(i=0;i<size;i++)
		{
			bar(getxy(i).lx,getxy(i).ly,getxy(i).rx,getxy(i).ry);
		}
}
Esempio n. 20
0
void tty_erase_sos (void)
{
#ifdef _WIN32
	unsigned	x, y;

	getxy (&x, &y);
	tty_erase_sol ();
	if (y > tty_start_y)
		setregion (tty_start_x, tty_start_y,
			   ' ', tty_attribs,
			   tty_max_x - tty_start_x + 1, y - tty_start_y);
#else
	printf ("\x1b[1J");
	fflush (stdout);
#endif
}
Esempio n. 21
0
/*
*route of the timer irq.
*scheduler will goes from here.
*/	
void timer_irq()
{
	timefly++;
	if(timefly%2==0)
	{
		char buf[25];
		int oldx,oldy;
		getxy(&oldx,&oldy);
		gotoxy(60,23);
		//kprint(itoa(timefly,buf,10));
		kprintf("%d\n", timefly);
		//kprint("ok\n");
		gotoxy(50,21);
		kprintf("%s\n", timetostr(update_sys_time(timefly), buf));
		//kprint( timetostr(update_sys_time(timefly),buf) );
		gotoxy(oldx,oldy);
	}
	schedule();
	
	outportb(0x20,0x20);
}
Esempio n. 22
0
void heroTurn(Hero& hero, ArmoredEnemy& enemy)
{
	std::string userInput;
	short x, y;
	getxy(x, y);
	std::cout << R"( |                      Would you like to:                     |
 |     1. Attack the Enemy 2. Try to block the next attack     |
 |                                                             |
 |                                                             |
 ---------------------------------------------------------------)";
	do
	{
		gotoxy(24, y + 2);
		std::cout << "                                       ";
		gotoxy(24, y + 2);
		getline(std::cin, userInput);
		transform(userInput.begin(), userInput.end(), userInput.begin(), tolower);
		gotoxy(64, y + 2);
		std::cout << "Please enter";
		gotoxy(64, y + 3);
		std::cout << "1 or 2";
	} while(userInput[0] != 'a' && userInput[0] != 'b' && userInput[0] != '1' && userInput[0] != '2');
Esempio n. 23
0
File: polygon.c Progetto: cran/secr
void fx1 (double *x, int n, void *ex) {
    int i;
    int ns;
    int fn;
/*    struct rpoint *line;*/
    struct rpoint line[maxvertices * 2];
    struct rpoint mxy;
    struct rpoint xy;
    double * p;
    double cumd[maxvertices * 2];
    double d;
    fnptr fnzr = zhnr;
    /* extract parameters passed in void pointer ex */
    p = (double*) ex;
    fn = round(p[3]);
    mxy.x = p[4];
    mxy.y = p[5];
    ns = round(p[9]);
    /* coordinates of vertices */
/*    line = (struct rpoint *) R_alloc(ns, sizeof(struct rpoint));*/
    for (i=0; i<ns; i++) {
        line[i].x = p[i+10];
        line[i].y = p[i+ns+10];
    }
    /* cumulative distance along line */
    /* cumd = (double *) R_alloc(ns + 1, sizeof(double)); */
    cumd[0] = 0;
    for (i=0; i<(ns-1); i++) {
        cumd[i+1] = cumd[i] + distance (line[i],line[i+1]);
    }
    /* set detection function - default zhnr */
    fnzr = getzfnr(fn);  // 2016-01-02, 2017-03-22
    /* for each x in x[] */
    for (i=0; i<n; i++) {
        xy = getxy (x[i], cumd, line, ns, 0);
        d = distance (xy, mxy);
        x[i] = fnzr(p, d);   /* z(r) */
    }
}
Esempio n. 24
0
File: img.cpp Progetto: FrankHB/YEGE
int
gety(IMAGE* pimg)
{
	return getxy(pimg).y;
}
Esempio n. 25
0
void	main(void)
{
 char	local_map[9][9]; 	/* Buffer to hold the local map */
 int	x_pos,			/* Current X and Y coordinates of robot */
	y_pos;
 int	go_dir;			/* current direction (index to angle[]) */
 int	scan_angle=0;		/* Current scanning angle */
 int	range;			/* range returned from the scan routine */
 int	try;

/* Configure robot - all normal settings in this case
 * This *MUST* be the first special function called by the robot   */
 configure(2,2,2,2,2,0);

 randomize();

 go_dir=random(8);		/* Select initial direction */

/* Note - this is an *INFINITE* loop - the PCROBOTS executive program
   kills the robot off when necessary*/
 while(1)
 {
/* Get the current position */
  getxy(&x_pos,&y_pos);

/* Get a map of the local area */
  get_local_map((char *)local_map);

/* Quick and easy way of dealing with the robot being near an outside wall */
  if (x_pos<20)
   go_dir=(random(3)-1)%8;
  if (x_pos>=980)
   go_dir=random(3)+3;
  if (y_pos<20)
   go_dir=random(3)+1;
  if (y_pos>=980)
   go_dir=random(3)+5;

  try=0;
/* Look for a square which hasn't got a wall in it (ignore traps in this
 * simple program) */
  while (local_map[angle[go_dir].y][angle[go_dir].x] == ARENA_WALL)
  {
   go_dir=random(8);

/* Failsafe check to avoid the program getting trapped here */
   if (try++ > 10)
    break;
  }

/* Move in the new direction */
  movement(50,angle[go_dir].angle);

/* Check if target found, shoot at it if so, otherwise go to next angle */
  if (scan(scan_angle,5,&range)>=0)
  {
	if(!shells_left()) buy_shells(1);
   shoot(scan_angle,range);
  }
  else
   scan_angle=(scan_angle+5)%360;

 }
}
Esempio n. 26
0
int main()
{
	struct tsdev *ts;
	int fd;
	calibration cal;
	int cal_fd;
	char cal_buffer[256];
	char *tsdevice = NULL;
	char *calfile = NULL;
	int i;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
		ts = ts_open(tsdevice,0);
	} else {
#if 0
#ifdef USE_INPUT_API
		ts = ts_open("/dev/input/event0", 0);
#else
		ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif /* USE_INPUT_API */
#else
	ts = ts_open("/dev/input/event2", 0);
#endif
	}

	if (!ts) {
		perror("ts_open");
		exit(1);
	}
#if 0
	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}
#endif

	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}
	close_framebuffer();
	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}

	setcolors(0x48ff48,0x880000);

	put_string(xres/2,yres/4,"TSLIB calibration utility",1);
	put_string(xres/2,yres/4 + 20,"Touch crosshair to calibrate",1);

	printf("xres = %d, yres = %d\n",xres,yres);

// Read a touchscreen event to clear the buffer
	//getxy(ts, 0, 0);

// Now paint a crosshair on the upper left and start taking calibration
// data
	put_cross(50,50,1);
	getxy(ts, &cal.x[0], &cal.y[0]);
	put_cross(50,50,0);

	cal.xfb[0] = 50;
	cal.yfb[0] = 50;

	printf("Top left : X = %4d Y = %4d\n", cal.x[0], cal.y[0]);

	put_cross(xres - 50, 50, 1);
	getxy(ts, &cal.x[1], &cal.y[1]);
	put_cross(xres - 50, 50, 0);

	cal.xfb[1] = xres-50;
	cal.yfb[1] = 50;

	printf("Top right: X = %4d Y = %4d\n", cal.x[1], cal.y[1]);

	put_cross(xres - 50, yres - 50, 1);
	getxy(ts, &cal.x[2], &cal.y[2]);
	put_cross(xres - 50, yres - 50, 0);

	cal.xfb[2] = xres-50;
	cal.yfb[2] = yres-50;

	printf("Bot right: X = %4d Y = %4d\n", cal.x[2], cal.y[2]);

	put_cross(50, yres - 50, 1);
	getxy(ts, &cal.x[3], &cal.y[3]);
	put_cross(50, yres - 50, 0);

	cal.xfb[3] = 50;
	cal.yfb[3] = yres-50;

	printf("Bot left : X = %4d Y = %4d\n", cal.x[3], cal.y[3]);

	put_cross(xres/2, yres/2, 1);
	getxy(ts, &cal.x[4], &cal.y[4]);
	put_cross(xres/2, yres/2, 0);

	cal.xfb[4] = xres/2;
	cal.yfb[4] = yres/2;

	printf("Middle: X = %4d Y = %4d\n", cal.x[4], cal.y[4]);

	if(perform_calibration(&cal)) {
		printf("Calibration constants: ");
		for(i=0;i<7;i++) printf("%d ",cal.a[i]);
		printf("\n");
		if( (calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
			cal_fd = open(calfile,O_CREAT|O_RDWR);
		} else {
			cal_fd = open("/etc/pointercal",O_CREAT|O_RDWR);
		}
		sprintf(cal_buffer,"%d %d %d %d %d %d %d\n",cal.a[1],cal.a[2],cal.a[0],cal.a[4],cal.a[5],cal.a[3],cal.a[6]);
		write(cal_fd,cal_buffer,strlen(cal_buffer)+1);
		close(cal_fd);	
	} else {
		printf("Calibration failed.\n");
	}

//	while (1) {
//		struct ts_sample samp;
//
//		if (ts_read_raw(ts, &samp, 1) < 0) {
//			perror("ts_read");
//			exit(1);
//		}
//
//		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
//			samp.x, samp.y, samp.pressure);
//	}
	close_framebuffer();
}
Esempio n. 27
0
/* main */
int main(int argc, char **argv) {
  getxy();
  printf("%d %s %d %s", coords[0], ",", coords[1], "\n");
  return 0;
}
Esempio n. 28
0
  /* Refresh the screen. If FULL is true, redraw the full line, otherwise,
     only LEN characters from LPOS.  */
  void cl_refresh (int full, int len)
    {
      int i;
      int start;
      int pos = xpos;
      
      if (full)
	{
	  /* Recompute the section number.  */
	  if (lpos + plen < CMDLINE_WIDTH)
	    section = 0;
	  else
	    section = ((lpos + plen - CMDLINE_WIDTH)
		       / (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN) + 1);

	  /* From the start to the end.  */
	  len = CMDLINE_WIDTH;
	  pos = 0;
	  grub_putchar ('\r');

	  /* If SECTION is the first section, print the prompt, otherwise,
	     print `<'.  */
	  if (section == 0)
	    {
	      grub_printf ("%s", prompt);
	      len -= plen;
	      pos += plen;
	    }
	  else
	    {
	      grub_putchar ('<');
	      len--;
	      pos++;
	    }
	}

      /* Compute the index to start writing BUF and the resulting position
	 on the screen.  */
      if (section == 0)
	{
	  int offset = 0;
	  
	  if (! full)
	    offset = xpos - plen;
	  
	  start = 0;
	  xpos = lpos + plen;
	  start += offset;
	}
      else
	{
	  int offset = 0;
	  
	  if (! full)
	    offset = xpos - 1;
	  
	  start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
		   + CMDLINE_WIDTH - plen - CMDLINE_MARGIN);
	  xpos = lpos + 1 - start;
	  start += offset;
	}

      /* Print BUF. If ECHO_CHAR is not zero, put it instead.  */
      for (i = start; i < start + len && i < llen; i++)
	{
	  if (! echo_char)
	    grub_putchar (buf[i]);
	  else
	    grub_putchar (echo_char);

	  pos++;
	}
      
      /* Fill up the rest of the line with spaces.  */
      for (; i < start + len; i++)
	{
	  grub_putchar (' ');
	  pos++;
	}
      
      /* If the cursor is at the last position, put `>' or a space,
	 depending on if there are more characters in BUF.  */
      if (pos == CMDLINE_WIDTH)
	{
	  if (start + len < llen)
	    grub_putchar ('>');
	  else
	    grub_putchar (' ');
	  
	  pos++;
	}
      
      /* Back to XPOS.  */
      if (current_term->flags & TERM_DUMB)
	{
	  for (i = 0; i < pos - xpos; i++)
	    grub_putchar ('\b');
	}
      else
	gotoxy (xpos, getxy () & 0xFF);
    }
Esempio n. 29
0
static int
real_get_cmdline (char *prompt, char *cmdline, int maxlen,
		  int echo_char, int readline)
{
  /* This is a rather complicated function. So explain the concept.
     
     A command-line consists of ``section''s. A section is a part of the
     line which may be displayed on the screen, but a section is never
     displayed with another section simultaneously.

     Each section is basically 77 or less characters, but the exception
     is the first section, which is 78 or less characters, because the
     starting point is special. See below.

     The first section contains a prompt and a command-line (or the
     first part of a command-line when it is too long to be fit in the
     screen). So, in the first section, the number of command-line
     characters displayed is 78 minus the length of the prompt (or
     less). If the command-line has more characters, `>' is put at the
     position 78 (zero-origin), to inform the user of the hidden
     characters.

     Other sections always have `<' at the first position, since there
     is absolutely a section before each section. If there is a section
     after another section, this section consists of 77 characters and
     `>' at the last position. The last section has 77 or less
     characters and doesn't have `>'.

     Each section other than the last shares some characters with the
     previous section. This region is called ``margin''. If the cursor
     is put at the magin which is shared by the first section and the
     second, the first section is displayed. Otherwise, a displayed
     section is switched to another section, only if the cursor is put
     outside that section.  */

  /* XXX: These should be defined in shared.h, but I leave these here,
     until this code is freezed.  */
#define CMDLINE_WIDTH	78
#define CMDLINE_MARGIN	10
  
  int xpos, lpos, c, section;
  /* The length of PROMPT.  */
  int plen;
  /* The length of the command-line.  */
  int llen;
  /* The index for the history.  */
  int history = -1;
  /* The working buffer for the command-line.  */
  char *buf = (char *) CMDLINE_BUF;
  /* The kill buffer.  */
  char *kill_buf = (char *) KILL_BUF;
  
  /* Nested function definitions for code simplicity.  */

  /* The forward declarations of nested functions are prefixed
     with `auto'.  */
  auto void cl_refresh (int full, int len);
  auto void cl_backward (int count);
  auto void cl_forward (int count);
  auto void cl_insert (const char *str);
  auto void cl_delete (int count);
  auto void cl_init (void);
  
  /* Move the cursor backward.  */
  void cl_backward (int count)
    {
      lpos -= count;
      
      /* If the cursor is in the first section, display the first section
	 instead of the second.  */
      if (section == 1 && plen + lpos < CMDLINE_WIDTH)
	cl_refresh (1, 0);
      else if (xpos - count < 1)
	cl_refresh (1, 0);
      else
	{
	  xpos -= count;

	  if (current_term->flags & TERM_DUMB)
	    {
	      int i;
	      
	      for (i = 0; i < count; i++)
		grub_putchar ('\b');
	    }
	  else
	    gotoxy (xpos, getxy () & 0xFF);
	}
    }
Esempio n. 30
0
File: img.cpp Progetto: FrankHB/YEGE
int
getx(IMAGE* pimg)
{
	return getxy(pimg).x;
}