コード例 #1
0
ファイル: optsmenu.c プロジェクト: gsrr/Python
static void tetrom_colors_menu(int x, int y)
{
	const char *menu[7] = {"I", "J", "L", "O", "S", "T", "Z"};
	menuhandler handlers[7] = {
		op_tcolor, op_tcolor, op_tcolor, op_tcolor,
		op_tcolor_gt4, op_tcolor_gt4, op_tcolor_gt4
	};
	int i = 0;
	if (y+6 >= term_height)
		y -= 7;
	drawbox(x, y, 19, 6, (char *) 0);
	x++;
	y++;
	drawmenu(menu, 4, 0, x, y, handlers);
	drawmenu(menu+4, 3, -1, x+9, y, handlers+4);
	autorep_a_b_btns = 1;
	while (1) {
		setcurs(x, y+i%4);
		refreshwin(-1);
		switch (handle_menuitem_2cols(menu, 7, &i, 4, x, y+i%4,
				handlers, getkeypress_block(SINGLE_PL))) {
		case 0:
		case 2:
			autorep_a_b_btns = 0;
			if (i >= 4)
				x -= 9;
			clearbox(x-1, y-1, 19, 6);
			return;
		case 3:
			x += i>=4 ? 9 : -9;
			setcurs(x, y+i%4);
			printmenuitem(menu[i], 1);
		}
	}
}
コード例 #2
0
ファイル: gameover.c プロジェクト: williamiced/SocketTetris
static int hiscore_entername_menu(char *name, const char **menu, int x, int y)
{
	int pos = 0;
	int i = 0;
	int k;
	while (1) {
		drawmenu(menu, 2, i-2, x, y+2, NULL);
textbox:	setcurs(x, y);
		printtextbox(name, pos);
		movefwd(3);
		printsavebutton(!i && pos==7);
		if (!i)
			x += pos;
		setcurs(x, y+i);
		refreshwin(-1);
		autorep_a_b_btns = 1;
		k = getkeypress_block(SINGLE_PL) & 0xFF;
		autorep_a_b_btns = 0;
		if (k == ESC)
			return 0;
		if (!i) {
			x -= pos;
			switch (k) {
			case STARTBTN:
				return 1;
			case '\t':
				if (pos < 7)
					break;
			case MVDOWN:
				i = 2;
				continue;
			}
			pos = hiscore_editname(name, pos, k);
			goto textbox;
		}
		switch (k) {
		case STARTBTN:
		case A_BTN:
			if (i==2)
				return 2;
		case 'q':
			exit(0);
		case MVUP:
			i = i==2 ? 0 : 2;
			break;
		case '\t':
			i = i==2 ? 3 : 0;
			break;
		case MVDOWN:
			if (i < 3)
				i++;
		}
		if (!i && pos==7) {
			pos = 6;
			while (pos && name[pos-1]==' ')
				pos--;
		}
	}
}
コード例 #3
0
ファイル: thingmenu.c プロジェクト: singpolyma/thingmenu
void
expose(XEvent *e)
{
    XExposeEvent *ev = &e->xexpose;

    if(ev->count == 0 && (ev->window == win))
        drawmenu();
}
コード例 #4
0
ファイル: menu.c プロジェクト: stqism/DEMOS
getmenu ()
{
	if (! menu[0].len)
		initmenu ();

	getboxes ();
	VMPutString (LINES-1, 0, "\0011\16      \17 2\16      \17 3\16      \17 4\16      \17 5\16      \17 6\16      \17 7\16      \17 8\16      \17 9\16      \01710\16Quit \17\2");
	for (;;) {
		drawhead (nmenu);
		for (;;) {
			drawmenu (&menu[nmenu]);
			hidecursor ();
			VSync ();
			switch (KeyGet ()) {
			default:
				VBeep ();
				continue;
			case cntrl (']'):          /* redraw screen */
				VRedraw ();
				continue;
			case cntrl ('M'):
				clrmenu (&menu[nmenu]);
				return (1);
			case cntrl ('J'):
				clrmenu (&menu[nmenu]);
				return (2);
			case cntrl ('C'):
			case cntrl ('['):
			case meta ('J'):        /* f0 */
				clrmenu (&menu[nmenu]);
				return (0);
			case meta ('r'):        /* right */
				clrmenu (&menu[nmenu]);
				if (! menu[++nmenu].mname)
					nmenu = 0;
				break;
			case meta ('l'):        /* left */
				clrmenu (&menu[nmenu]);
				if (--nmenu < 0) {
					for (nmenu=0; menu[nmenu].mname; ++nmenu);
					--nmenu;
				}
				break;
			case meta ('u'):        /* up */
				upmenu (&menu[nmenu]);
				continue;
			case meta ('d'):        /* down */
				downmenu (&menu[nmenu]);
				continue;
			}
			break;
		}
	}
}
コード例 #5
0
ファイル: dmenu.c プロジェクト: stilvoid/dmenu
void
paste(void) {
    char *p, *q;
    int di;
    unsigned long dl;
    Atom da;

    XGetWindowProperty(dc->dpy, win, utf8, 0, (sizeof text / 4) + 1, False,
                       utf8, &da, &di, &dl, &dl, (unsigned char **)&p);
    insert(p, (q = strchr(p, '\n')) ? q-p : strlen(p));
    XFree(p);
    drawmenu();
}
コード例 #6
0
ファイル: GRAPHS.C プロジェクト: rickytan/Snooker
void restore()									/****恢复屏幕到主菜单****/
{
	int i;
	cleardevice();
	putimage(0,0,logo,COPY_PUT);
	for (i=0;i<STARNUM;i++) drawstar(star);

	outchinese(400,80,s_cn,EOF,4,0);
	drawmenu(mm);
	drawmouse(mousex,mousey);
	if (Music_on) play(2);
	else noplay();
}
コード例 #7
0
ファイル: Main.cpp プロジェクト: KevinRoeschke/CIDE
//Windows Main
void Main::execute (void)
{
	char ip;
	do
	{
		drawmenu();
		ip = getchar();

		fflush(stdin);
		executecommand_sub(ip);
	}
	while( ip != '\n' );
}
コード例 #8
0
ファイル: dmenu.c プロジェクト: OliverUv/dmenu-q-xywh-xft
void
paste(void) {
	char *p, *q;
	int di;
	unsigned long dl;
	Atom da;

	/* we have been given the current selection, now insert it into input */
	XGetWindowProperty(dc->dpy, win, utf8, 0, (sizeof text / 4) + 1, False,
	                   utf8, &da, &di, &dl, &dl, (unsigned char **)&p);
	insert(p, (q = strchr(p, '\n')) ? q-p : (ssize_t)strlen(p));
	XFree(p);
	drawmenu();
}
コード例 #9
0
ファイル: vis-menu.c プロジェクト: larryhynes/vis
static void
setup(void) {
	int fd, result = -1;
	struct winsize ws;

	/* re-open stdin to read keyboard */
	if (!freopen("/dev/tty", "r", stdin)) die("Can't reopen tty.");

	/* ioctl() the tty to get size */
	fd = open("/dev/tty", O_RDWR);
	if (fd == -1) {
		mh = 24;
		mw = 80;
	} else {
		result = ioctl(fd, TIOCGWINSZ, &ws);
		close(fd);
		if (result < 0) {
			mw = 80;
			mh = 24;
		} else {
			mw = ws.ws_col;
			mh = ws.ws_row;
		}
	}

	/* change terminal attributes, save old */
	tcgetattr(0, &tio_old);
	tio_new = tio_old;
	tio_new.c_iflag &= ~(BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
	tio_new.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
	tio_new.c_cflag &= ~(CSIZE|PARENB);
	tio_new.c_cflag |= CS8;
	tio_new.c_cc[VMIN] = 1;
	tcsetattr(0, TCSANOW, &tio_new);

	lines = MIN(MAX(lines, 0), mh);
	promptw = prompt ? textw(prompt) : 0;
	inputw = MIN(inputw, mw/3);
	match();
	if (barpos != 0) resetline();
	drawmenu();
}
コード例 #10
0
ファイル: menucore.c プロジェクト: gsrr/Python
int openmenu(const char **menu, int n, int i, int x, int y,
	     menuhandler *handlers)
{
	drawmenu(menu, n, i, x, y, handlers);
	while (1) {
		setcurs(x, y+i);
		refreshwin(-1);		/* refresh active window */

		switch (handle_menuitem(menu, n, &i, x, y+i, handlers,
					getkeypress_block(SINGLE_PL))) {
		case 0:
			return 0;
		case 2:
			return i+1;
#if !NO_MENU
		case 3:
			return openmenu(menu, n, i, x, y, handlers);
#endif
		}
	}
}
コード例 #11
0
ファイル: dmenu.c プロジェクト: stilvoid/dmenu
void
run(void) {
    XEvent ev;

    while(!XNextEvent(dc->dpy, &ev))
        switch(ev.type) {
        case Expose:
            if(ev.xexpose.count == 0)
                drawmenu();
            break;
        case KeyPress:
            keypress(&ev.xkey);
            break;
        case SelectionNotify:
            if(ev.xselection.property == utf8)
                paste();
            break;
        case VisibilityNotify:
            if(ev.xvisibility.state != VisibilityUnobscured)
                XRaiseWindow(dc->dpy, win);
            break;
        }
}
コード例 #12
0
ファイル: GRAPHS.C プロジェクト: rickytan/Snooker
void beforegame()								/******游戏主界面*******/
{
	int i,j;

	fire();

	ShowBmp256(70,65,".\\source\\login.bmp",1,0);

	InitGraph();
	star=malloc(sizeof(struct STAR)*STARNUM);
	initstar(star);
	InitMouse(0,0,maxx,maxy);

	getdat();
	handler=getvect(0x1c);

	mousex=getmaxx()/2;
	mousey=getmaxy()/2;

	logo=bmp_to_dat(".\\source\\snooker.bmp");
	vs1=bmp_to_dat(".\\source\\head0.bmp");
	vs2=bmp_to_dat(".\\source\\head1.bmp");

	play(1);
	for (i=0;i<3;i++)
	{
		putimage(0,0,logo,NOT_PUT);
		for (j=20;j<=1000;j+=10)
		{
			delay(1000);
		}
		delay(3000);
		putimage(0,0,logo,COPY_PUT);
		for (j=1000;j>=20;j-=10)
		{
			delay(2000);
		}
		delay(3000);
	}
	putimage(0,0,logo,COPY_PUT);
	for (i=0;i<STARNUM;i++) drawstar(star);

	outchinese(400,80,s_cn,EOF,4,2);
	putimage(300,280,vs1,COPY_PUT);
	putimage(520,280,vs2,COPY_PUT);

	settextstyle(1,0,12);
	setcolor(GREEN);
	outtextxy(380,260,"Vs");

	drawmouse(mousex,mousey);
	play(2);
	drawmenu(mm);
	while(1)
	{
		while(bioskey(1)!=0) getch();
		position(1);
		mm=fill();
		drawmouse(mousex,mousey);
		if (button==1)
		{
			switch (mm)
			{
				case 0:
					{
						free(logo);
						free(star);
						cleardevice();
						return;
					}
				case 1:
					{
						practice();
						restore();
						break;
					}
				case 2:
					{
						noplay();
						option();
						break;
					}
				case 3:
					{
						noplay();
						toprank();
						restore();
						break;
					}
				case 4:
					{
						if (Music_on==1) play(0);
						showhelp();
						break;
					}
				case 5:
					{
						position(0);
						End(1);
						drawmouse(mousex,mousey);
						break;
					}
			}
		}
		button=0;
	}
}
コード例 #13
0
ファイル: ChaTTY.c プロジェクト: heron--/ChaTTY
void menuloop()
{
	int c;
	int highlight = 0;
	drawmenu(highlight);
	while(c = wgetch(stdscr)) {
		switch(c) {
			case 'w':
				if(highlight) highlight--; // If highlight is not zero decrement it
				break;
			case 's':
				if(highlight < 3) highlight++;
				break;
			case 'a':
				if(highlight) highlight--;
				break;
			case 'd':
				if(highlight < 3) highlight++;
				break;
			case KEY_UP:
				if(highlight) highlight--;
				break;
			case KEY_DOWN:
				if(highlight < 3) highlight++;
				break;
			case KEY_LEFT:
				if(highlight) highlight--;
				break;
			case KEY_RIGHT:
				if(highlight < 3) highlight++;
				break;
			case ' ':
				if(translatehighlight(highlight) < 0) return;
				break;
			case 'X':
				sendloop();
				break;
			case 'x':
				sendloop();
				break;
			case 'R': 
				reqloop();
				break;
			case 'r': 
				reqloop();
				break;
			case 'C':
				convloop(); 
				break;
			case 'c':
				convloop(); 
				break;
			case 'Q':
				return;
			case 'q':
				return;
			default: break;
		}
		drawmenu(highlight);
	}
}
コード例 #14
0
ファイル: help.c プロジェクト: CivilPol/sdcboot
int
main (int argc, char *argv[])
{
  /* These have been moved from global to local variables */
  /* this reduces binary size and improves code structure. RP */
  /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */
  char home_page[20] = "index.htm";
  char help_page[20] = "help.htm";
  char base_dir[257];

  char *showcommand = 0;
  char *oldscreen;
  int oldcursorx = wherex (), oldcursory = wherey ();
  int i;			/* counter for loop */
  int forcemono = 0, fancyscheme = 0;
  int AsciiExtendedChars = 1;
  int codepage = 0;

  cat = catopen("htmlhelp", 0);

  if (getenv ("HELPPATH") == NULL)
    {
      get_base_dir (base_dir, argv[0]);
      strcat (base_dir, "..\\help\\"); /* default location */

      if (lang_add(base_dir, home_page) != 0)
      {
         char testpath[257];
         get_base_dir (base_dir, argv[0]);
         strcat (base_dir, "..\\help\\"); /* bookshelf location */

         strcpy(testpath, base_dir);
         strcat(testpath, home_page);
         if (checkForFile(testpath) != 0)
         {
            get_base_dir (base_dir, argv[0]); /* try same dir as exe */
            strcpy(testpath, base_dir);
            strcat(testpath, home_page);
            if (checkForFile(testpath) != 0)
            {
               *base_dir = '\0'; /* try current dir */
               strcpy(testpath, home_page);
               if (checkForFile(testpath) != 0)
               {
                  get_base_dir (base_dir, argv[0]);
                  strcat (base_dir, "..\\help\\");
               }
            }
         }
      }
    }
  else
    {
      strcpy (base_dir, getenv ("HELPPATH"));
      if (lang_add(base_dir, home_page) != 0)
      {
         strcpy (base_dir, getenv ("HELPPATH"));
         if (base_dir[0] != '\0')
         {
            if (base_dir[strlen(base_dir)-1] != '\\' &&
                base_dir[strlen(base_dir)-1] != '/');
	            strcat (base_dir, "\\");
         }
      }

    }

  if (getenv ("HELPCMD"))
    {
      if (strstr (getenv ("HELPCMD"), "/A"))
	AsciiExtendedChars = 0;
      if (strstr (getenv ("HELPCMD"), "/M"))
	forcemono = 1;
      if (strstr (getenv ("HELPCMD"), "/F1"))
         fancyscheme = 1;
      if (strstr (getenv ("HELPCMD"), "/F2"))
         fancyscheme = 2;
    }

  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '/')
	{
	  switch (argv[i][1])
	    {

	    default:
	      printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		   printf ("%s\n", hcatHowGetUsage);
         break;

	    case '?':
	      show_usage ();
	      return 0;

	    case 'a':
	    case 'A':
	      if (argv[i][2] == 0)
		AsciiExtendedChars = 0;
	      break;

       case 'c':
       case 'C':
       codepage = atoi(argv[i]+2);
       if (codepage == 0)
       {
          printf("%s (/Cnnn)\n", hcatCodepagePlease);
          printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
          return 0;
       }
       break;

	    case 'f':
	    case 'F':
	      fancyscheme = atoi(argv[i] + 2);
         if (fancyscheme < 1 || fancyscheme > 2)
            fancyscheme = 1;
         break;

	    case 'h':
	    case 'H':
	      if (argv[i][2] == 0)	/* Only put /h or /H */
		{
        printf ("%s\n", hcatInvArg);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      else
		{
           strncpy(help_page, argv[i] + 2, 14);
		}
	      break;

	    case 'l':
	    case 'L':
	      strcat (base_dir, argv[i] + 2);
	      checkForFile (base_dir);
	      get_home_page (home_page, base_dir);
	      get_base_dir (base_dir, base_dir);
	      break;

	    case 'm':
	    case 'M':
	      if (argv[i][2] == '\0')
		forcemono = 1;
	      else
		{
		  printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      break;

	    case 'o':		/* Override index file path/name */
	    case 'O':
	      strcpy (base_dir, argv[i] + 2);
         if (lang_add(base_dir, home_page) != 0)
         {
	         strcpy (base_dir, argv[i] + 2);
	         checkForFile (base_dir);
	         get_home_page (home_page, base_dir);
	         get_base_dir (base_dir, base_dir);
         }
	    }
	}
      else if (showcommand == 0)
	{
	  showcommand = malloc (strlen (argv[i]) + 11);
	  if (!showcommand)
	    {
	      printf ("%s\n", hcatMemErr);
	      return 0;
	    }
	  sprintf (showcommand, "#%s", argv[i]);
	}
      else
	{
	  printf ("%s\n", hcat2ManyTopics);
	  printf ("%s\n", hcatHowGetUsage);
	  return 0;
	}
    }

  if (fancyscheme && forcemono)
  {
     printf ("%s\n", hcatFwithN);
	  printf ("%s\n", hcatHowGetUsage);
     return 0;
  }

  /* detect (or force) the codepage to select UTF-8 and entity
     substition support */
  if (selectCodepage(codepage) != codepage && codepage > 0)
  {
     printf("%s\n", hcatCodepageNotSupported);
     printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
     return 0;
  }

  /* initialise user interface */
  conio_init (forcemono);

  if (forcemono == 0)
    {
      oldscreen = malloc (W * H * 2);
      if (oldscreen)
	save_window (X, Y, W, H, oldscreen);
    }

  if (MonoOrColor == COLOR_MODE && fancyscheme == 0)
    {
      TEXT_COLOR = C_TEXT_COLOR;
      BOLD_COLOR = C_BOLD_COLOR;
      ITALIC_COLOR = C_ITALIC_COLOR;
      BORDER_BOX_COLOR = C_BORDER_COLOR;
      BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR;
      LINK_COLOR = C_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 1)
    {
      TEXT_COLOR = F1_TEXT_COLOR;
      BOLD_COLOR = F1_BOLD_COLOR;
      ITALIC_COLOR = F1_ITALIC_COLOR;
      BORDER_BOX_COLOR = F1_BORDER_COLOR;
      BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR;
      LINK_COLOR = F1_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 2)
    {
      TEXT_COLOR = F2_TEXT_COLOR;
      BOLD_COLOR = F2_BOLD_COLOR;
      ITALIC_COLOR = F2_ITALIC_COLOR;
      BORDER_BOX_COLOR = F2_BORDER_COLOR;
      BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR;
      LINK_COLOR = F2_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR;
    }
  else
    {
      TEXT_COLOR = M_TEXT_COLOR;
      BOLD_COLOR = M_BOLD_COLOR;
      ITALIC_COLOR = M_ITALIC_COLOR;
      BORDER_BOX_COLOR = M_BORDER_COLOR;
      BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR;
      LINK_COLOR = M_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR;
    }
  if (AsciiExtendedChars == 0)
    {
      strcpy (Border22f, "+-+( )+-+");
      strcpy (Border22if, "+-+( )+-+");
      BarBlock1 = '.';
      BarBlock2 = '#';
    }
  show_mouse ();
  move_mouse (80, 25);
  drawmenu ();
  html_view (showcommand, base_dir, home_page, help_page);
  free (showcommand);
  hide_mouse ();
  if ((oldscreen != 0) && (forcemono == 0))
    {
      load_window (X, Y, W, H, oldscreen);
      free (oldscreen);
    }
  conio_exit ();
  gotoxy (oldcursorx, oldcursory);

  return 0;
}
コード例 #15
0
ファイル: inputset.c プロジェクト: gsrr/Python
void inputsetup_menu(int pl, int x, int y)
{
	const char *menu[11] = {
		" Up", "Dwn", "Lft", "Rgt", "  A", "  B",
		" Rotate ", " Rot cw ", NULL, "Harddrop", "Softdrop"
	};
	char rot_acw[9] = " Rot acw";
	int dev = 0;
	int i = 0;
	int xx, k;
#ifdef JOYSTICK
	int devlist = num_joyst;
	if (devlist) {
		i = -1;
		setcurs(x, y);
		newln(x);
		y++;
	}
#endif
	spellword(rot_acw+5);
	menu[8] = rot_acw;
	drawmenu(menu, 6, i, x, y, NULL);
	drawmenu(menu+6, 5, -1, x+12, y, NULL);
#ifdef TWOPLAYER
	player_ = pl;
#endif
	while (1) {
#ifdef JOYSTICK
		if (devlist && i==-1) {
			if (!inp_devlist(&dev, x, y-1))
				return;
			printmenuitem(menu[0], 1);
			i = 0;
		}
#endif
		inp_printkeys(dev, x, y);
		xx = inp_setcurs(x, y, i);
		refreshwin(-1);
		k = setkeymapping(dev, inp_keypr(i));
#ifdef JOYSTICK
		if (devlist && (k==MVUP && !i || k=='\t' && i==10)) {
			printmenuitem(menu[i], 0);
			i = -1;
			continue;
		}
#endif
		if (k==MVUP && !i)
			k = MVDOWN;
		else if (k==MVDOWN && i==10) {
			printmenuitem(menu[10], 0);
			inp_setcurs(x, y, i=0);
			printmenuitem(menu[0], 1);
			continue;
		}
		switch (handle_menuitem_2cols(menu, 11, &i, 6,
					      xx, y+i%6, NULL, k)) {
		case 0:
		case 2:
			return;
		case 3:
			inp_setcurs(x, y, i);
			printmenuitem(menu[i], 1);
		}
	}
}
コード例 #16
0
static int menu(void) {
    clear();
    drawmenu(0);
    star_t* stars = malloc(sizeof(star_t) * numstars);
    init(stars);

    int frame;
    int key, choice = 0;
    SETPOS(ROWS, COLS);
    while (1) {
        for (frame = 0; frame < fps / FPS; frame++)
            update(stars);
        display(stars);
        drawmenu(choice);
        switch ((key = getkey())) {
        case KEY_UP:
        case 'w':
            xt_par0(XT_CH_DEFAULT);
            switch (choice) { // makes the previous button 'normal'
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    printf("Settings");
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            if (choice > 0)
                choice--;
            else
                choice = 3;
            xt_par0(XT_CH_BOLD);
            xt_par0(XT_CH_INVERSE);
            switch (choice) { // makes the button highlighted
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    SETPOS(ROWS, COLS);
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    xt_par0(XT_CH_BOLD);
                    printf("Settings");
                    SETPOS(ROWS, COLS);
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    SETPOS(ROWS, COLS);
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            xt_par0(XT_CH_NORMAL);
            break;
        case KEY_DOWN:
        case 's':
            xt_par0(XT_CH_DEFAULT);
            switch (choice) { // makes the previous button 'normal'
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    printf("Settings");
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    break;
                case 1:
                    SETPOS(ROWS / 2 + 1 * OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
            }
            if (choice < 3)
                choice++;
            else
                choice = 0;
            xt_par0(XT_CH_BOLD);
            xt_par0(XT_CH_INVERSE);
            switch (choice) { // makes the button highlighted
                case 0:
                    SETPOS(ROWS / 2, COLS / 2 - 6);
                    xt_par0(XT_CH_GREEN);
                    printf("Single Player");
                    SETPOS(ROWS, COLS);
                    break;
                case 2:
                    SETPOS(ROWS / 2 + 2 * OFFSET, COLS / 2 - 4);
                    xt_par0(XT_CH_WHITE);
                    xt_par0(XT_CH_BOLD);
                    printf("Settings");
                    SETPOS(ROWS, COLS);
                    break;
                case 3:
                    SETPOS(ROWS / 2 + 3 * OFFSET, COLS / 2 - 2);
                    xt_par0(XT_CH_RED);
                    printf("Quit");
                    SETPOS(ROWS, COLS);
                    break;
                case 1:
                    SETPOS(ROWS / 2 + OFFSET, COLS / 2 - 5);
                    xt_par0(XT_CH_RED);
                    xt_par0(XT_CH_BOLD);
                    printf("M");
                    xt_par0(XT_CH_YELLOW);
                    printf("u");
                    xt_par0(XT_CH_GREEN);
                    printf("L");
                    xt_par0(XT_CH_CYAN);
                    printf("t");
                    xt_par0(XT_CH_BLUE);
                    printf("I");
                    xt_par0(XT_CH_MAGENTA);
                    printf("p");
                    xt_par0(XT_CH_RED);
                    printf("L");
                    xt_par0(XT_CH_YELLOW);
                    printf("a");
                    xt_par0(XT_CH_GREEN);
                    printf("Y");
                    xt_par0(XT_CH_CYAN);
                    printf("e");
                    xt_par0(XT_CH_BLUE);
                    printf("R");
                    break;
                }
                xt_par0(XT_CH_NORMAL);
                break;
            case KEY_ENTER:
                return choice;
            case 'q':
                return MENU_QUIT;
        }
        fflush(stdout);
        usleep(1000000/FPS);

    }
}
コード例 #17
0
ファイル: dmenu.c プロジェクト: OliverUv/dmenu-q-xywh-xft
void
keypress(XKeyEvent *ev) {
	char buf[32];
	int len;
	KeySym ksym = NoSymbol;
	Status status;

	len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
	if(status == XBufferOverflow)
		return;
	if(ev->state & ControlMask)
		switch(ksym) {
		case XK_a: ksym = XK_Home;      break;
		case XK_b: ksym = XK_Left;      break;
		case XK_c: ksym = XK_Escape;    break;
		case XK_d: ksym = XK_Delete;    break;
		case XK_e: ksym = XK_End;       break;
		case XK_f: ksym = XK_Right;     break;
		case XK_g: ksym = XK_Escape;    break;
		case XK_h: ksym = XK_BackSpace; break;
		case XK_i: ksym = XK_Tab;       break;
		case XK_j: /* fallthrough */
		case XK_J: ksym = XK_Return;    break;
		case XK_m: /* fallthrough */
		case XK_M: ksym = XK_Return;    break;
		case XK_n: ksym = XK_Down;      break;
		case XK_p: ksym = XK_Up;        break;

		case XK_k: /* delete right */
			text[cursor] = '\0';
			match();
			break;
		case XK_u: /* delete left */
			insert(NULL, 0 - cursor);
			break;
		case XK_w: /* delete word */
			while(cursor > 0 && text[nextrune(-1)] == ' ')
				insert(NULL, nextrune(-1) - cursor);
			while(cursor > 0 && text[nextrune(-1)] != ' ' && text[nextrune(-1)] != '/')
				insert(NULL, nextrune(-1) - cursor);
			break;
		case XK_y: /* paste selection */
			XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
			                  utf8, utf8, win, CurrentTime);
			return;
		default:
			return;
		}
	else if(ev->state & Mod1Mask)
		switch(ksym) {
		case XK_g: ksym = XK_Home;  break;
		case XK_G: ksym = XK_End;   break;
		case XK_h: ksym = XK_Up;    break;
		case XK_j: ksym = XK_Next;  break;
		case XK_k: ksym = XK_Prior; break;
		case XK_l: ksym = XK_Down;  break;
		default:
			return;
		}
	switch(ksym) {
	default:
		if(!iscntrl(*buf))
			insert(buf, len);
		break;
	case XK_Delete:
		if(text[cursor] == '\0')
			return;
		cursor = nextrune(+1);
		/* fallthrough */
	case XK_BackSpace:
		if(cursor == 0)
			return;
		insert(NULL, nextrune(-1) - cursor);
		break;
	case XK_End:
		if(text[cursor] != '\0') {
			cursor = strlen(text);
			break;
		}
		if(next) {
			/* jump to end of list and position items in reverse */
			curr = matchend;
			calcoffsets();
			curr = prev;
			calcoffsets();
			while(next && (curr = curr->right))
				calcoffsets();
		}
		sel = matchend;
		break;
	case XK_Escape:
        ret = EXIT_FAILURE;
        running = False;
	case XK_Home:
		if(sel == matches) {
			cursor = 0;
			break;
		}
		sel = curr = matches;
		calcoffsets();
		break;
	case XK_Left:
		if(cursor > 0 && (!sel || !sel->left || lines > 0)) {
			cursor = nextrune(-1);
            break;
		}
		if(lines > 0)
			return;
		/* fallthrough */
	case XK_Up:
		if(sel && sel->left && (sel = sel->left)->right == curr) {
			curr = prev;
			calcoffsets();
		}
		break;
	case XK_Next:
		if(!next)
			return;
		sel = curr = next;
		calcoffsets();
		break;
	case XK_Prior:
		if(!prev)
			return;
		sel = curr = prev;
		calcoffsets();
		break;
	case XK_Return:
	case XK_KP_Enter:
		puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
		ret = EXIT_SUCCESS;
		running = False;
	case XK_Right:
		if(text[cursor] != '\0') {
			cursor = nextrune(+1);
            break;
		}
		if(lines > 0)
			return;
		/* fallthrough */
	case XK_Down:
		if(sel && sel->right && (sel = sel->right) == next) {
			curr = next;
			calcoffsets();
		}
		break;
	case XK_Tab:
		if(!sel)
			return;
		strncpy(text, sel->text, sizeof text);
		cursor = strlen(text);
		match();
		break;
	}
	drawmenu();
}
コード例 #18
0
ファイル: graphics.c プロジェクト: sundargates/qed-examples
void event_loop (void (*act_on_button) (float x, float y), 
    void (*drawscreen) (void)) {

/* The program's main event loop.  Must be passed a user routine        *
 * drawscreen which redraws the screen.  It handles all window resizing *
 * zooming etc. itself.  If the user clicks a button in the graphics    *
 * (toplevel) area, the act_on_button routine passed in is called.      */

 XEvent report;
 int bnum;
 float x, y;

#define OFF 1
#define ON 0

 turn_on_off (ON);
 while (1) {
    XNextEvent (display, &report);
    switch (report.type) {  
    case Expose:
#ifdef VERBOSE 
       printf("Got an expose event.\n");
       printf("Count is: %d.\n",report.xexpose.count);
       printf("Window ID is: %d.\n",report.xexpose.window);
#endif
       if (report.xexpose.count != 0)
           break;
       if (report.xexpose.window == menu)
          drawmenu(); 
       else if (report.xexpose.window == toplevel)
          drawscreen();
       else if (report.xexpose.window == textarea)
          draw_message();
       break;
    case ConfigureNotify:
       top_width = report.xconfigure.width;
       top_height = report.xconfigure.height;
       update_transform();
#ifdef VERBOSE 
       printf("Got a ConfigureNotify.\n");
       printf("New width: %d  New height: %d.\n",top_width,top_height);
#endif
       break; 
    case ButtonPress:
#ifdef VERBOSE 
       printf("Got a buttonpress.\n");
       printf("Window ID is: %d.\n",report.xbutton.window);
#endif
       if (report.xbutton.window == toplevel) {
          x = XTOWORLD(report.xbutton.x);
          y = YTOWORLD(report.xbutton.y); 
          act_on_button (x, y);
       } 
       else {  /* A menu button was pressed. */
          bnum = which_button(report.xbutton.window);
#ifdef VERBOSE 
       printf("Button number is %d\n",bnum);
#endif
          button[bnum].ispressed = 1;
          drawbut(bnum);
          XFlush(display);  /* Flash the button */
          button[bnum].fcn(bnum, drawscreen);
          button[bnum].ispressed = 0;
          drawbut(bnum);
          if (button[bnum].fcn == proceed) {
             turn_on_off(OFF);
             flushinput ();
             return;  /* Rather clumsy way of returning *
                       * control to the simulator       */
          }
       }
       break;
    }
 }
}
コード例 #19
0
ファイル: help_htm.c プロジェクト: CivilPol/sdcboot
int
html_view_internal (struct eventState *pes, char *base_dir, char *home_page)
{
  int i;

  if (pes->link_text != 0)
    {
      statusbar (hcatStatusLooking);
      if (*pes->link_text == '#')
	{
	  char *anchor;

	  if (strnicmp (pes->link_text + 1, HTMLHELP_INTERNAL_SEARCHLINK,
			strlen (HTMLHELP_INTERNAL_SEARCHLINK)) == 0)
	    {
	      /* Internal search engine link */
	      anchor = pes->body_start + atoi (pes->link_text +
					       strlen
					       (HTMLHELP_INTERNAL_SEARCHLINK)
					       + 1);
	    }
	  else
	    {
	      sprintf (pes->text_holder, "<a name=\"%.*s\"",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      anchor = strstr (pes->body_start, pes->text_holder);
	    }

	  if (anchor)
	    {
	      /* Locate start of line. */
	      while (anchor != pes->body_start && *anchor != '\n')
		anchor--;

	      if (*anchor == '\n')
		anchor++;

	      /* Move to this line, just near top of screen */
         if (!pes->first_time)
            addBookmark(pes);
	      pes->seek_base = anchor;
	      pes->seek_cnt = -1;
         pes->clink = 0; /* RP - Added 5.3.2 */
	      pes->link_text = 0;
	      *pes->text_holder = 0;
	      statusbar (NULL);
	      return NAVIGATE_DONT;
	    }
	  else
	    {
	      int triedasfile = 0;
         int tryexact = 1;
	      sprintf (pes->text_holder, "%.*s",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      strlwr (pes->text_holder);
		   write_string (TEXT_COLOR, X + strlen(hcatStatusLooking) + 3, TY,
				                       hcatStatusEscape);
	      do
		{

		  pes->p = pes->body_start;
		  while ((pes->p = strstr (pes->p, "<a")) != 0)
		    {
		      static struct event ev;
		      get_event (&ev, EV_KEY | EV_NONBLOCK);
		      if (ev.ev_type == EV_KEY && ev.key == 27)
			{
			  pes->link_text = 0;
           show_error(hcatUserAborted);
			  return NAVIGATE_DONT;
			}

		      pes->p = strchr (pes->p, '>');
		      if (pes->p)
			{
			  ++(pes->p);
			  if ((strnicmp(pes->p, pes->text_holder,
			                        strlen (pes->text_holder)) == 0) &&
                (pes->p[strlen(pes->text_holder)] == '<' || !tryexact))
			    {
			      while (pes->p != pes->body_start &&
				     strncmp (pes->p, "<a", 2))
				pes->p--;

			      pes->p = strstr (pes->p, "href=");
			      if (pes->p != 0)
				{
				  pes->p += 6;
				  if (*pes->p == '\"')
				    pes->p++;

				  if (*pes->p == '#')
				    break;

				  if (prepare_link (pes))
				    {
                  if (tryexact == 0)
                     show_error(hcatNoExactFound);
				      return NAVIGATE_LINK;
				    }
				}
			    }
			}
		    }
		  if (triedasfile == 0)
		    {
		      int undostrcat = strlen (base_dir);
		      if (base_dir[strlen (base_dir) - 1] != '\\'
			  && base_dir[0] != 0)
			strcat (base_dir, "\\");
		      strcat (base_dir, pes->text_holder);
		      if (checkForFile (base_dir))
			{
			  /* Didn't work */
			  base_dir[undostrcat] = '\0';
			}
		      else
			{
			  if (pes->first_time)
			    pes->hidden = 1;
			  get_home_page (home_page, base_dir);
			  get_base_dir (base_dir, base_dir);
			  return NAVIGATE_HOME;
			}
		      triedasfile = 1;
		    }
		  else
		    {
            /* don't try to match end with the < */
            if (tryexact)
            {
               tryexact = 0;
            }
            else
            {
		         pes->p = pes->text_holder + strlen (pes->text_holder) - 1;
		         if (*pes->p > 'a')
			         --(*pes->p);
		         else
			         *pes->p = 0;
            }
		    }
		}
	      while (*(pes->text_holder) != 0);
	    }
     statusbar (NULL);

	  sprintf (pes->text_holder, "%s '%.*s'", hcatCouldntFind,
		   link_length (pes->link_text + 1), pes->link_text + 1);
	  show_error (pes->text_holder);
	  pes->link_text = 0;
	  *(pes->text_holder) = 0;
	  return NAVIGATE_DONT;
	}
      else if (prepare_link (pes))
	return NAVIGATE_LINK;

      pes->link_text = 0;
    }

  if (pes->first_time)
  {
     drawmenu();
     save_window (X, Y, W, H, pes->screen_buf);
     pes->first_time = 0;
  }

  if (pes->seek_cnt != 0)
    {
      if (pes->seek_cnt <= 0)
	{
	  i = -pes->seek_cnt;
	  pes->p = pes->seek_base - 1;
	  if (*pes->p == '\n')
	    pes->p--;

	  for (; (pes->p != pes->body_start); pes->p--)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }
	  pes->top = pes->p;
	}
      else if (pes->seek_cnt > 0)
	{
	  i = pes->seek_cnt;
	  pes->p = pes->seek_base;
	  for (; pes->p != pes->body_end; pes->p++)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }

	  if (pes->p == pes->body_end)
	    {
	      pes->seek_base = pes->body_end - 1;
	      pes->seek_cnt = -1;
	      return NAVIGATE_DONT;
	    }

	  pes->top = pes->p;
	}
      pes->seek_cnt = 0;
    }

  if (pes->maxtop != 0)
    pes->barpos = ((pes->top - pes->body_start) * BARLEN) / pes->maxtop;
  else
    pes->barpos = BARLEN - 1;

  if (pes->barpos >= BARLEN || pes->barpos < 0)	/* <0 fix - RP */
    pes->barpos = BARLEN - 1;

  if (pes->bar_hooked)
    {
      pes->seek_base = pes->top;
      if (pes->forced_barpos == 0)
	{
	  pes->top = pes->body_start;
	  pes->barpos = 0;
	}
      else if (pes->forced_barpos == BARLEN - 1
	       && pes->barpos != pes->forced_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_base = pes->body_end;
	  pes->seek_cnt = -N;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos < pes->barpos
	       && pes->forced_barpos < pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = -1;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos > pes->barpos
	       && pes->forced_barpos > pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = +1;
	  return NAVIGATE_DONT;
	}
    }

  pes->old_barpos = pes->barpos;
  if (pes->top != pes->old_top)
    pes->force_redraw = 1;

  /* ------ Display processing ------------------------------------ */
  displayProcess (pes);

  /* ------ Event processing -------------------------------------- */
  return processEvents (pes);
}
コード例 #20
0
ファイル: dmenu.c プロジェクト: OliverUv/dmenu-q-xywh-xft
void
setup(void) {
	int x, y, screen = DefaultScreen(dc->dpy);
	Window root = RootWindow(dc->dpy, screen);
	XSetWindowAttributes swa;
	XIM xim;
#ifdef XINERAMA
	int n;
	XineramaScreenInfo *info;
#endif

	clip = XInternAtom(dc->dpy, "CLIPBOARD",   False);
	utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);

	/* calculate menu geometry */
	bh = (line_height > dc->font.height + 2) ? line_height : dc->font.height + 2;
	lines = MAX(lines, 0);
	mh = (lines + 1) * bh;
#ifdef XINERAMA
	if((info = XineramaQueryScreens(dc->dpy, &n))) {
		int a, j, di, i = 0, area = 0;
		unsigned int du;
		Window w, pw, dw, *dws;
		XWindowAttributes wa;

		XGetInputFocus(dc->dpy, &w, &di);
		if(w != root && w != PointerRoot && w != None) {
			/* find top-level window containing current input focus */
			do {
				if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws)
					XFree(dws);
			} while(w != root && w != pw);
			/* find xinerama screen with which the window intersects most */
			if(XGetWindowAttributes(dc->dpy, pw, &wa))
				for(j = 0; j < n; j++)
					if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
						area = a;
						i = j;
					}
		}
		/* no focused window is on screen, so use pointer location instead */
		if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
			for(i = 0; i < n; i++)
				if(INTERSECT(x, y, 1, 1, info[i]))
					break;

		x = info[i].x_org;
		y = info[i].y_org + (topbar ? yoffset : info[i].height - mh - yoffset);
		mw = info[i].width;
		XFree(info);
	}
	else
#endif
	{
		x = 0;
		y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh - yoffset;
		mw = DisplayWidth(dc->dpy, screen);
	}

	x += xoffset;
	mw = width ? width : mw;
	promptw = (prompt && *prompt) ? textw(dc, prompt) : 0;
	inputw = MIN(inputw, mw/3);
	match();

	/* create menu window */
	swa.override_redirect = True;
	swa.background_pixel = normcol->BG;
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
	win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
	                    DefaultDepth(dc->dpy, screen), CopyFromParent,
	                    DefaultVisual(dc->dpy, screen),
	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);

	/* open input methods */
	xim = XOpenIM(dc->dpy, NULL, NULL, NULL);
	xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
	                XNClientWindow, win, XNFocusWindow, win, NULL);

	XMapRaised(dc->dpy, win);
	resizedc(dc, mw, mh);
	drawmenu();
}
コード例 #21
0
ファイル: yaed.c プロジェクト: BackupTheBerlios/yaed
void cursormoved(file_t *file)
{
	if(file->cursor_y >= file->scroll_y + h-1-3)
	{
		/* scroll screen up */
		while(file->cursor_y >= file->scroll_y + h-1-h/3)
		{
			file->scroll_y++;
			
			if(current >= 0 && file == files[current])
			{
				/* scroll screen */
				
				scrollok(screen, TRUE);
				scrl(1);
				scrollok(screen, FALSE);
				
				/* draw bottom line */
				if(h-2 + file->scroll_y < file->line_count)
					drawline(file, h-2 + file->scroll_y);
				
				drawmenu();
				refresh();
				
				napms(5);
			}
		}
	}
	
	if(file->cursor_y < file->scroll_y + 3 && file->scroll_y)
	{
		/* scroll screen down */
		while(file->cursor_y < file->scroll_y + h/3 && file->scroll_y)
		{
			file->scroll_y--;
			
			if(current >= 0 && file == files[current])
			{
				/* scroll screen */
				
				scrollok(screen, TRUE);
				scrl(-1);
				scrollok(screen, FALSE);
				
				/* draw top line */
				
				drawline(file, file->scroll_y);
				drawmenu();
				refresh();
				
				napms(5);
			}
		}
	}
	
	/* modify selection */
	if(file->selected && ((file->cursor_x >= file->sel_begin_x
	&& file->cursor_y == file->sel_begin_y) || file->cursor_y > file->sel_begin_y))
	{
		file->sel_end_x = file->cursor_x;
		file->sel_end_y = file->cursor_y;
		
		if(current >= 0 && file == files[current])
			drawscreen();
	}
	
	if(current >= 0 && file == files[current])
		drawpos();
}
コード例 #22
0
ファイル: yaed.c プロジェクト: BackupTheBerlios/yaed
int main(int argc, char **argv)
{
	struct termios term, term_saved;
	file_t *file;
	
	if(argc > 2)
	{
		printf("ERROR: Invalid arguments!\n");
		return 1;
	}
	
	newfile();
	
	file = files[0];
	
	if(argc == 2)
	{
		/* filename given */
		strcpy(file->filename, argv[1]);
		loadfile(file, argv[1]);
	}
	else
		file->filename[0] = 0;
	
	file->saved = 1;
	
	current = 0;
	
	/* make sure we got something */
	if(!file->line_count)
		insertline(file, 0);
	
	file->cursor_x = 0;
	file->cursor_y = 0;
	
	tcgetattr(0, &term_saved);
	
	/* initialize curses */
	screen = initscr();
	cbreak();
	nonl();
	noecho();
	
	keypad(screen, TRUE);
	
	/* modify terminal settings */
	tcgetattr(0, &term);
	term.c_lflag &= ~(IEXTEN | ISIG);
	term.c_iflag &= ~IXON;
	term.c_oflag &= ~OPOST;	
	tcsetattr(0, TCSANOW, &term);
	
	/* setup colors */
	start_color();
	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
	init_pair(2, COLOR_WHITE, COLOR_BLACK);
	init_pair(3, COLOR_WHITE, COLOR_BLUE);
	init_pair(4, COLOR_WHITE, COLOR_BLUE);
	init_pair(5, COLOR_GREEN, COLOR_BLACK);
	init_pair(6, COLOR_BLUE, COLOR_BLACK);
	init_pair(7, COLOR_BLACK, COLOR_BLACK);
	attron(COLOR_PAIR(2));
	
	getmaxyx(screen, h, w);
	
	drawmenu();	
	drawscreen();
	drawpos();
	
	setcursor();
	refresh();
	
	/* main loop */
	while(!editor_loop());
	
	endwin();
	
	/* revert terminal settings */
	tcsetattr(0, TCSANOW, &term_saved);
	
	return 0;
}
コード例 #23
0
ファイル: dmenu.c プロジェクト: stilvoid/dmenu
void
keypress(XKeyEvent *ev) {
    char buf[32];
    size_t len;
    KeySym ksym;

    len = strlen(text);
    XLookupString(ev, buf, sizeof buf, &ksym, NULL);
    if(ev->state & ControlMask) {
        switch(tolower(ksym)) {
        default:
            return;
        case XK_a:
            ksym = XK_Home;
            break;
        case XK_b:
            ksym = XK_Left;
            break;
        case XK_c:
            ksym = XK_Escape;
            break;
        case XK_d:
            ksym = XK_Delete;
            break;
        case XK_e:
            ksym = XK_End;
            break;
        case XK_f:
            ksym = XK_Right;
            break;
        case XK_h:
            ksym = XK_BackSpace;
            break;
        case XK_i:
            ksym = XK_Tab;
            break;
        case XK_j:
            ksym = XK_Return;
            break;
        case XK_k:  /* delete right */
            text[cursor] = '\0';
            match();
            break;
        case XK_n:
            ksym = XK_Down;
            break;
        case XK_p:
            ksym = XK_Up;
            break;
        case XK_u:  /* delete left */
            insert(NULL, 0 - cursor);
            break;
        case XK_w:  /* delete word */
            while(cursor > 0 && text[nextrune(-1)] == ' ')
                insert(NULL, nextrune(-1) - cursor);
            while(cursor > 0 && text[nextrune(-1)] != ' ')
                insert(NULL, nextrune(-1) - cursor);
            break;
        case XK_y:  /* paste selection */
            XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime);
            return;
        }
    }
    switch(ksym) {
    default:
        if(!iscntrl(*buf))
            insert(buf, strlen(buf));
        break;
    case XK_Delete:
        if(cursor == len)
            return;
        cursor = nextrune(+1);
    case XK_BackSpace:
        if(cursor > 0)
            insert(NULL, nextrune(-1) - cursor);
        break;
    case XK_End:
        if(cursor < len) {
            cursor = len;
            break;
        }
        while(next) {
            sel = curr = next;
            calcoffsets();
        }
        while(sel && sel->right)
            sel = sel->right;
        break;
    case XK_Escape:
        exit(EXIT_FAILURE);
    case XK_Home:
        if(sel == matches) {
            cursor = 0;
            break;
        }
        sel = curr = matches;
        calcoffsets();
        break;
    case XK_Left:
        if(cursor > 0 && (!sel || !sel->left || lines > 0)) {
            cursor = nextrune(-1);
            break;
        }
        else if(lines > 0)
            return;
    case XK_Up:
        if(sel && sel->left && (sel = sel->left)->right == curr) {
            curr = prev;
            calcoffsets();
        }
        break;
    case XK_Next:
        if(!next)
            return;
        sel = curr = next;
        calcoffsets();
        break;
    case XK_Prior:
        if(!prev)
            return;
        sel = curr = prev;
        calcoffsets();
        break;
    case XK_Return:
    case XK_KP_Enter:
        handle_return((sel && !(ev->state & ShiftMask)) ? sel->text : text);
    case XK_Right:
        if(cursor < len) {
            cursor = nextrune(+1);
            break;
        }
        else if(lines > 0)
            return;
    case XK_Down:
        if(sel && sel->right && (sel = sel->right) == next) {
            curr = next;
            calcoffsets();
        }
        break;
    case XK_Tab:
        if(!sel)
            return;
        strncpy(text, sel->text, sizeof text);
        cursor = strlen(text);
        match();
        break;
    }
    drawmenu();
}
コード例 #24
0
ファイル: dmenu.c プロジェクト: temochka/dmenu
static void
setup(void)
{
	int x, y;
	XSetWindowAttributes swa;
	XIM xim;
#ifdef XINERAMA
	XineramaScreenInfo *info;
	Window w, pw, dw, *dws;
	XWindowAttributes wa;
	int a, j, di, n, i = 0, area = 0;
	unsigned int du;
#endif

	/* init appearance */
	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
	scheme[SchemeOut].bg = drw_clr_create(drw, outbgcolor);
	scheme[SchemeOut].fg = drw_clr_create(drw, outfgcolor);

	clip = XInternAtom(dpy, "CLIPBOARD",   False);
	utf8 = XInternAtom(dpy, "UTF8_STRING", False);

	/* calculate menu geometry */
	bh = drw->fonts[0]->h + 2;
	lines = MAX(lines, 0);
	mh = (lines + 1) * bh;
#ifdef XINERAMA
	if ((info = XineramaQueryScreens(dpy, &n))) {
		XGetInputFocus(dpy, &w, &di);
		if (mon != -1 && mon < n)
			i = mon;
		if (!i && w != root && w != PointerRoot && w != None) {
			/* find top-level window containing current input focus */
			do {
				if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
					XFree(dws);
			} while (w != root && w != pw);
			/* find xinerama screen with which the window intersects most */
			if (XGetWindowAttributes(dpy, pw, &wa))
				for (j = 0; j < n; j++)
					if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
						area = a;
						i = j;
					}
		}
		/* no focused window is on screen, so use pointer location instead */
		if (mon == -1 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
			for (i = 0; i < n; i++)
				if (INTERSECT(x, y, 1, 1, info[i]))
					break;

		x = info[i].x_org;
		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
		mw = info[i].width;
		XFree(info);
	} else
#endif
	{
		x = 0;
		y = topbar ? 0 : sh - mh;
		mw = sw;
	}
	promptw = (prompt && *prompt) ? TEXTW(prompt) : 0;
	inputw = MIN(inputw, mw/3);
	match();

	/* create menu window */
	swa.override_redirect = True;
	swa.background_pixel = scheme[SchemeNorm].bg->pix;
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
	win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
	                    DefaultDepth(dpy, screen), CopyFromParent,
	                    DefaultVisual(dpy, screen),
	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);

	/* open input methods */
	xim = XOpenIM(dpy, NULL, NULL, NULL);
	xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
	                XNClientWindow, win, XNFocusWindow, win, NULL);

	XMapRaised(dpy, win);
	drw_resize(drw, mw, mh);
	drawmenu();
}
コード例 #25
0
ファイル: file1.c プロジェクト: AnshB/Ncurses-final-project
int main() {
	int key, menuitem, ent, id;
	menuitem = 0;
	initscr();
	drawmenu(menuitem);
	keypad(stdscr,TRUE);
	
	noecho();
	do {
		key = getch();
		switch(key) {
			case KEY_DOWN: menuitem++;
			if(menuitem > MENUMAX-1) 
				menuitem = 0;
			break;

			case KEY_UP: menuitem--;
			if(menuitem < 0) 
				menuitem = MENUMAX-1;
			break;

			default: 
			break;

		}

		drawmenu(menuitem);
		
		ent = getch();
	
		if(menuitem == 0 && ent == KEY_RIGHT) { 
			login();
			refresh();
		}
		else if(menuitem == 1 && ent == KEY_RIGHT) {
			register_id();
			refresh();
		}
		else if(menuitem == 2 && ent == KEY_RIGHT) { 
			findtrain();
			refresh();
		}
		else if(menuitem == 3 && ent == KEY_RIGHT) { 
			printw("Enter train id\n");			
			scanw("%d", &id);
			CheckAvailibility(id);
			refresh();
		}	
		else if(menuitem == 4 && ent == KEY_RIGHT) { 
			cancelticket();
			refresh();
		}
		else if(menuitem == 5 && ent == KEY_RIGHT) { 
			DisplayQueueac();
			refresh();
		}
		else if(menuitem == 6 && ent == KEY_RIGHT) { 
			DisplayQueuesl();
			refresh();
		}
		else if(menuitem == 7 && ent == KEY_RIGHT) { 
			exit(1);
		}
	}	
	while(key != '\n');
		echo();      /*Shows the text*/
	
	endwin();
	return 0;

}
コード例 #26
0
ファイル: vis-menu.c プロジェクト: larryhynes/vis
static int
run(void) {
	char buf[32];
	char c;

	for (;;) {
		xread(0, &c, 1);
		memset(buf, '\0', sizeof buf);
		buf[0] = c;
		switch_top:
		switch(c) {
		case CONTROL('['):
			xread(0, &c, 1);
			esc_switch_top:
			switch(c) {
			case CONTROL('['): /* ESC, need to press twice due to console limitations */
				c = CONTROL('C');
				goto switch_top;
			case '[':
				xread(0, &c, 1);
				switch(c) {
				case '1': /* Home */
				case '7':
				case 'H':
					if (c != 'H') xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = CONTROL('A');
					goto switch_top;
				case '2': /* Insert */
					xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = CONTROL('Y');
					goto switch_top;
				case '3': /* Delete */
					xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = CONTROL('D');
					goto switch_top;
				case '4': /* End */
				case '8':
				case 'F':
					if (c != 'F') xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = CONTROL('E');
					goto switch_top;
				case '5': /* PageUp */
					xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = CONTROL('V');
					goto switch_top;
				case '6': /* PageDown */
					xread(0, &c, 1); /* Remove trailing '~' from stdin */
					c = 'v';
					goto esc_switch_top;
				case 'A': /* Up arrow */
					c = CONTROL('P');
					goto switch_top;
				case 'B': /* Down arrow */
					c = CONTROL('N');
					goto switch_top;
				case 'C': /* Right arrow */
					c = CONTROL('F');
					goto switch_top;
				case 'D': /* Left arrow */
					c = CONTROL('B');
					goto switch_top;
				}
				break;
			case 'b':
				while (cursor > 0 && text[nextrune(-1)] == ' ')
					cursor = nextrune(-1);
				while (cursor > 0 && text[nextrune(-1)] != ' ')
					cursor = nextrune(-1);
				break;
			case 'f':
				while (text[cursor] != '\0' && text[nextrune(+1)] == ' ')
					cursor = nextrune(+1);
				if (text[cursor] != '\0') {
					do {
						cursor = nextrune(+1);
					} while (text[cursor] != '\0' && text[cursor] != ' ');
				}
				break;
			case 'd':
				while (text[cursor] != '\0' && text[nextrune(+1)] == ' ') {
					cursor = nextrune(+1);
					insert(NULL, nextrune(-1) - cursor);
				}
				if (text[cursor] != '\0') {
					do {
						cursor = nextrune(+1);
						insert(NULL, nextrune(-1) - cursor);
					} while (text[cursor] != '\0' && text[cursor] != ' ');
				}
				break;
			case 'v':
				if (!next)
					break;
				sel = curr = next;
				calcoffsets();
				break;
			default:
				break;
			}
			break;
		case CONTROL('C'):
			return EXIT_FAILURE;
		case CONTROL('M'): /* Return */
		case CONTROL('J'):
			if (sel) strncpy(text, sel->text, sizeof(text)-1); /* Complete the input first, when hitting return */
			cursor = strlen(text);
			match();
			drawmenu();
			/* fallthrough */
		case CONTROL(']'):
		case CONTROL('\\'): /* These are usually close enough to RET to replace Shift+RET, again due to console limitations */
			puts(text);
			return EXIT_SUCCESS;
		case CONTROL('A'):
			if (sel == matches) {
				cursor = 0;
				break;
			}
			sel = curr = matches;
			calcoffsets();
			break;
		case CONTROL('E'):
			if (text[cursor] != '\0') {
				cursor = strlen(text);
				break;
			}
			if (next) {
				curr = matchend;
				calcoffsets();
				curr = prev;
				calcoffsets();
				while(next && (curr = curr->right))
					calcoffsets();
			}
			sel = matchend;
			break;
		case CONTROL('B'):
			if (cursor > 0 && (!sel || !sel->left || lines > 0)) {
				cursor = nextrune(-1);
				break;
			}
			/* fallthrough */
		case CONTROL('P'):
			if (sel && sel->left && (sel = sel->left)->right == curr) {
				curr = prev;
				calcoffsets();
			}
			break;
		case CONTROL('F'):
			if (text[cursor] != '\0') {
				cursor = nextrune(+1);
				break;
			}
			/* fallthrough */
		case CONTROL('N'):
			if (sel && sel->right && (sel = sel->right) == next) {
				curr = next;
				calcoffsets();
			}
			break;
		case CONTROL('D'):
			if (text[cursor] == '\0')
				break;
			cursor = nextrune(+1);
			/* fallthrough */
		case CONTROL('H'):
		case CONTROL('?'): /* Backspace */
			if (cursor == 0)
				break;
			insert(NULL, nextrune(-1) - cursor);
			break;
		case CONTROL('I'): /* TAB */
			if (!sel)
				break;
			strncpy(text, sel->text, sizeof text);
			cursor = strlen(text);
			match();
			break;
		case CONTROL('K'):
			text[cursor] = '\0';
			match();
			break;
		case CONTROL('U'):
			insert(NULL, 0 - cursor);
			break;
		case CONTROL('W'):
			while (cursor > 0 && text[nextrune(-1)] == ' ')
				insert(NULL, nextrune(-1) - cursor);
			while (cursor > 0 && text[nextrune(-1)] != ' ')
				insert(NULL, nextrune(-1) - cursor);
			break;
		case CONTROL('V'):
			if (!prev)
				break;
			sel = curr = prev;
			calcoffsets();
			break;
		default:
			if (!iscntrl(*buf))
				insert(buf, strlen(buf));
			break;
		}
		drawmenu();
	}
}
コード例 #27
0
ファイル: yaed.c プロジェクト: BackupTheBerlios/yaed
/* editor event loop */
int editor_loop()
{
	int ch;
	file_t *file;
	
	file = files[current];
	
	ch = getch();
	switch(ch)
	{
	case KEY_RESIZE:
		getmaxyx(screen, h, w);
		
		drawmenu();	
		drawscreen();
		break;
	
	case KEY_F(5):
		/* display help */
		drawhelp();
		refresh();
		
		while(!help_loop());
		
		drawscreen();
		break;
	
	case KEY_F(6):
		/* save */
		if(file->filename[0])
		{
			writefile(file, file->filename);
			file->saved = 1;
		}
		break;
	
	case KEY_F(8):
		/* force quit */
		return 1;
	
	case KEY_F(9):
		/* toggle linenumbers */
		show_linenumbers = !show_linenumbers;
		drawscreen();
		break;
	
	case KEY_F(10):
		/* tab size */
		tab_size = !tab_size;
		drawscreen();
		break;
	
	case KEY_F(11):
		/* C highlight */
		c_highlight = !c_highlight;
		drawscreen();
		break;
	
	case 3:			/* control-C */
		if(file->selected)
		{
			/* TODO: copy */
		}
		break;
	
	case 11:		/* control-K */
		if(file->line_count > 1)
			removeline(file, file->cursor_y);
		break;
	
	case 22:		/* control-V */
		/* TODO: paste */
		break;
	
	case 24:		/* control-X */
		/* quit */
		
		/* TODO: check all open files */
		
		if(file->saved)
			return 1;
		break;
		
	case 19:		/* control-S */
		if(file->selected)
		{
			int y;
			
			/* end selection */
			
			file->selected = 0;
			for(y = file->sel_begin_y; y <= file->sel_end_y; y++)
				drawline(file, y);
		}
		else
		{
			/* begin selection */
			
			file->selected = 1;
			file->sel_begin_x = file->cursor_x;
			file->sel_begin_y = file->cursor_y;
			file->sel_end_x = file->cursor_x;
			file->sel_end_y = file->cursor_y;
		}
		break;
	
	case 21:		/* control-U */
		if(file->selected)
		{
			int y;
			
			/* un-indent lines */
			
			for(y = file->sel_begin_y; y <= file->sel_end_y; y++)
			{
				if(file->lines[y].len && file->lines[y].buf[0] == '\t')
					removetext(file, 0, y, 1);
			}
		}
		break;
	
	case KEY_PPAGE:
		/* move half screen up */
		if(file->cursor_y)
		{
			file->cursor_y -= h/2;
			if(file->cursor_y < 0)
				file->cursor_y = 0;
			
			/* don't go past end of line */
			if(file->cursor_x > file->lines[file->cursor_y].len)
				file->cursor_x = file->lines[file->cursor_y].len;
		}
		break;
	
	case KEY_NPAGE:
		/* move half screen down */
		if(file->cursor_y < file->line_count-1)
		{
			file->cursor_y += h/2;
			if(file->cursor_y > file->line_count-1)
				file->cursor_y = file->line_count-1;
			
			/* don't go past end of line */
			if(file->cursor_x > file->lines[file->cursor_y].len)
				file->cursor_x = file->lines[file->cursor_y].len;
		}
		break;
	
	case KEY_UP:
		if(file->cursor_y)
		{
			file->cursor_y--;
			
			/* don't go past end of line */
			if(file->cursor_x > file->lines[file->cursor_y].len)
				file->cursor_x = file->lines[file->cursor_y].len;
		}
		break;
	
	case KEY_DOWN:
		if(file->cursor_y < file->line_count-1)
		{
			file->cursor_y++;
			
			/* move cursor to line end */
			if(file->cursor_x > file->lines[file->cursor_y].len)
				file->cursor_x = file->lines[file->cursor_y].len;
		}
		break;
	
	case KEY_HOME:
		/* go to begin of line */
		if(file->cursor_x)
			file->cursor_x = 0;
		break;
	
	case KEY_END:
		/* go to end of line */
		if(file->cursor_x < file->lines[file->cursor_y].len)
			file->cursor_x = file->lines[file->cursor_y].len; 
		break;
	
	case KEY_LEFT:
		/* go to left one character */
		if(file->cursor_x)
			file->cursor_x--;
		else if(file->cursor_y)
		{
			/* jump to end of previous line */
			file->cursor_y--;
			file->cursor_x = file->lines[file->cursor_y].len;
		}
		break;
	
	case KEY_RIGHT:
		/* go right one character */
		if(file->cursor_x < file->lines[file->cursor_y].len)
			file->cursor_x++;
		else if(file->cursor_y < file->line_count-1)
		{
			/* jump to begin of next line */
			file->cursor_y++;
			file->cursor_x = 0;
		}
		break;
	
	case KEY_DC:
		if(file->selected)
		{
			file->selected = 0;
			
			/* delete selection */
			
			if(file->sel_begin_y == file->sel_end_y)
			{
				/* remove characters from current line */
				removetext(file, file->sel_begin_x, file->sel_begin_y,
					file->sel_end_x - file->sel_begin_x);
			}
			else
			{
				int y;
				line_t *line;
				
				/* remove ending from the first line */
				removetext(file, file->sel_begin_x, file->sel_begin_y,
					file->lines[file->sel_begin_y].len - file->sel_begin_x);
				
				/* copy ending from the last line to the end of first line */
				line = &file->lines[file->sel_end_y];
				if(file->sel_end_x < line->len)
				{
					inserttext(file, file->sel_begin_x, file->sel_begin_y,
						&line->buf[file->sel_end_x],
						line->len - file->sel_end_x);
				}
				
				/* remove all lines between the first and last line */
				for(y=0; y < file->sel_end_y-file->sel_begin_y; y++)
					removeline(file, file->sel_begin_y+1);
				
				file->cursor_x = file->sel_begin_x;
				file->cursor_y = file->sel_begin_y;
			}
		}
		else if(file->cursor_x < file->lines[file->cursor_y].len)
		{
			/* remove character from cursor position */
			removetext(file, file->cursor_x, file->cursor_y, 1);
		}
		break;
	
	case KEY_BACKSPACE:
	case '\b':
	case 127:
		if(file->cursor_x)
		{
			/* remove character from cursor position */
			file->cursor_x--;
			removetext(file, file->cursor_x, file->cursor_y, 1);
		}
		else if(file->cursor_y)
		{
			line_t *line;
			
			/* move to the end of the previous line */
			file->cursor_y--;
			file->cursor_x = file->lines[file->cursor_y].len;
			
			/* copy text from the next line to the end of current line */
			
			line = &file->lines[file->cursor_y+1];
			if(line->len)
			{
				inserttext(file, file->cursor_x, file->cursor_y,
					line->buf, line->len);
			}
			
			/* and remove the next line */
			removeline(file, file->cursor_y+1);
		}
		break;
	
	case '\r':
		{
			line_t *line;
			
			/* add new line */
			insertline(file, file->cursor_y+1);
			
			line = &file->lines[file->cursor_y];
			if(file->cursor_x < line->len)
			{
				/* copy ending from the current line to the next line */
				inserttext(file, 0, file->cursor_y+1,
					&line->buf[file->cursor_x], line->len - file->cursor_x);
				
				/* and remove ending from the current line */
				removetext(file, file->cursor_x, file->cursor_y,
					line->len - file->cursor_x);
			}
			
			/* move cursor to the begin of the next line */
			file->cursor_y++;
			file->cursor_x = 0;
		}
		break;
	
	case '\t':
		if(file->selected)
		{
			int y;
			
			/* indent lines */
			
			for(y = file->sel_begin_y; y <= file->sel_end_y; y++)
				inserttext(file, 0, y, "\t", 1);
			
			break;
		}
		/* fall trought */
	
	default:
		if((ch >= ' ' && ch < 256) || ch == '\t')
		{
			unsigned char buf = ch;
			
			/* insert character at cursor position */
			inserttext(file, file->cursor_x, file->cursor_y,
				(const char *)&buf, 1);
			file->cursor_x++;
		}
		break;
	}
	
	cursormoved(file);
	
	setcursor();
	refresh();
	
	return 0;
}
コード例 #28
0
ファイル: thingmenu.c プロジェクト: singpolyma/thingmenu
void
setup(void)
{
    XSetWindowAttributes wa;
    XTextProperty str;
    XSizeHints *sizeh;
    XClassHint *ch;
    int i, sh, sw, ls;

    /* init screen */
    screen = DefaultScreen(dpy);
    root = RootWindow(dpy, screen);
    sw = DisplayWidth(dpy, screen) - 1;
    sh = DisplayHeight(dpy, screen) - 1;
    initfont(font);

    /* init atoms */

    /* init appearance */

    for (i = 0, www = 0; i < nentries; i++) {
        ls = textnw(entries[i]->label,
                    strlen(entries[i]->label));
        if (ls > www)
            www = ls;
    }
    www *= widthscaling;

    if (!ww) {
        if (horizontal) {
            ww = www * nentries;
        } else {
            ww = www;
        }
    }
    if (!wh) {
        if (horizontal) {
            wh = dc.font.height * heightscaling;
        } else {
            wh = nentries * dc.font.height * heightscaling;
        }
    }
    if (!wy)
        wy = (sh - wh) / 2;
    if (wy < 0)
        wy = sh + wy - wh;
    if (!wx)
        wx = (sw - ww) / 2;
    if (wx < 0)
        wx = sw + wx - ww;

    dc.norm[ColBG] = getcolor(normbgcolor);
    dc.norm[ColFG] = getcolor(normfgcolor);
    dc.press[ColBG] = getcolor(pressbgcolor);
    dc.press[ColFG] = getcolor(pressfgcolor);
    dc.high[ColBG] = getcolor(highlightbgcolor);
    dc.high[ColFG] = getcolor(highlightfgcolor);

    dc.drawable = XCreatePixmap(dpy, root, ww, wh, DefaultDepth(dpy, screen));
    dc.gc = XCreateGC(dpy, root, 0, 0);
    if(!dc.font.set)
        XSetFont(dpy, dc.gc, dc.font.xfont->fid);
    for(i = 0; i < nentries; i++)
        entries[i]->pressed = 0;

    wa.override_redirect = !wmborder;
    wa.border_pixel = dc.norm[ColFG];
    wa.background_pixel = dc.norm[ColBG];
    win = XCreateWindow(dpy, root, wx, wy, ww, wh, 0,
                        CopyFromParent, CopyFromParent, CopyFromParent,
                        CWOverrideRedirect | CWBorderPixel | CWBackingPixel, &wa);
    XSelectInput(dpy, win, StructureNotifyMask|KeyReleaseMask|
                 ButtonReleaseMask|ButtonPressMask|
                 ExposureMask|LeaveWindowMask|PointerMotionMask);

    sizeh = XAllocSizeHints();
    sizeh->flags = PMaxSize | PMinSize;
    sizeh->min_width = sizeh->max_width = ww;
    sizeh->min_height = sizeh->max_height = wh;
    XStringListToTextProperty(&name, 1, &str);
    ch = XAllocClassHint();
    ch->res_class = name;
    ch->res_name = name;

    XSetWMProperties(dpy, win, &str, &str, NULL, 0, sizeh, NULL,
                     ch);

    XFree(ch);
    XFree(str.value);
    XFree(sizeh);

    XMapRaised(dpy, win);
    updateentries();
    drawmenu();
}
コード例 #29
0
ファイル: graphics.c プロジェクト: sundargates/qed-examples
static void adjustwin (int bnum, void (*drawscreen) (void)) {  
/* The window button was pressed.  Let the user click on the two *
 * diagonally opposed corners, and zoom in on this area.         */

 XEvent report;
 int corner, xold, yold, x[2], y[2];

 corner = 0;
 xold = -1;
 yold = -1;    /* Don't need to init yold, but stops compiler warning. */
 
 while (corner<2) {
    XNextEvent (display, &report);
    switch (report.type) {
    case Expose:
#ifdef VERBOSE 
       printf("Got an expose event.\n");
       printf("Count is: %d.\n",report.xexpose.count);
       printf("Window ID is: %d.\n",report.xexpose.window);
#endif
       if (report.xexpose.count != 0)
           break;
       if (report.xexpose.window == menu)
          drawmenu(); 
       else if (report.xexpose.window == toplevel) {
          drawscreen();
          xold = -1;   /* No rubber band on screen */
       }
       else if (report.xexpose.window == textarea)
          draw_message();
       break;
    case ConfigureNotify:
       top_width = report.xconfigure.width;
       top_height = report.xconfigure.height;
       update_transform();
#ifdef VERBOSE 
       printf("Got a ConfigureNotify.\n");
       printf("New width: %d  New height: %d.\n",top_width,top_height);
#endif
       break;
    case ButtonPress:
#ifdef VERBOSE 
       printf("Got a buttonpress.\n");
       printf("Window ID is: %d.\n",report.xbutton.window);
       printf("Location (%d, %d).\n", report.xbutton.x,
          report.xbutton.y);
#endif
       if (report.xbutton.window != toplevel) break;
       x[corner] = report.xbutton.x;
       y[corner] = report.xbutton.y; 
       if (corner == 0) {
       XSelectInput (display, toplevel, ExposureMask | 
         StructureNotifyMask | ButtonPressMask | PointerMotionMask);
       }
       else {
          update_win(x,y,drawscreen);
       }
       corner++;
       break;
    case MotionNotify:
#ifdef VERBOSE 
       printf("Got a MotionNotify Event.\n");
       printf("x: %d    y: %d\n",report.xmotion.x,report.xmotion.y);
#endif
       if (xold >= 0) {  /* xold set -ve before we draw first box */
          XDrawRectangle(display,toplevel,gcxor,min(x[0],xold),
             min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
       }
       /* Don't allow user to window under menu region */
       xold = min(report.xmotion.x,top_width-1-MWIDTH); 
       yold = report.xmotion.y;
       XDrawRectangle(display,toplevel,gcxor,min(x[0],xold),
          min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
       break;
    }
 }
 XSelectInput (display, toplevel, ExposureMask | StructureNotifyMask
                | ButtonPressMask); 
}
コード例 #30
0
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure

	s1.readInitFile();

	// Create Our OpenGL Window
	if (!b1.CreateGLWindow(winname,resset[0] [res],resset[1] [res],resset[2] [res],(bool)!fullres))
		return 0;									// Quit If Window Was Not Created

	TimerInit();

	glClearColor(0.0f,0.0f,0.0f,0.5f);

	BOOL escpress=FALSE;
	BOOL inmenu=FALSE;
	bool vspace=FALSE;

	while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
		
		if(intro)
		{
			runintro();
			SwapBuffers(hDC);
		}
		
		if(!intro)
		{
			
			float start=TimerGetTime();	
			
			if(keys[VK_ESCAPE] && !inmenu && !escpress)
			{
				inmenu=escpress=TRUE;
				shot.LoadSong("beep.mp3");
				oldres=res;
				oldfullres=fullres;
			}
			if(keys[VK_ESCAPE] && inmenu && !escpress)
			{
				inmenu=FALSE;
				shot.LoadSong("shot.mp3");
				escpress=TRUE;
			}
			if(!keys[VK_ESCAPE])
				escpress=FALSE;
			
			DrawGLScene();
			
			if(inmenu)
			{
				m1.testmovement();
				drawmenu();
			}
			
			if(!inmenu)
			{
				
				if(keys[VK_SPACE] && !vspace)
				{
					w1.shoot();
					vspace=TRUE;
				}
				if(!keys[VK_SPACE])
					vspace=FALSE;
				
				w1.testweapons();
				m1.testmovement();
				e1.testenemies();
				checkstuff();
				
				//remember to do all drawing BEFORE swap buffers!!!!!
				
				if(character.hurtcounter>0)
					character.hurtcounter--;
				
				if(character.life<0)
					character.life=0;
				
				if(keys[VK_DOWN])
					keys[VK_UP]=false;
				
				if(keys[VK_UP])
				{
					if(character.yvel<character.termvel)
						character.yvel+=.5;
					character.ypos-=character.yvel;
				}
				else
					character.yvel=0;
				
				if(!uppress && character.ypos<600)
				{
					character.ypos+=character.grav;
					character.grav+=.5;
				}
				else
					character.grav=2;
				
				if(character.ypos>600)
					character.ypos=600;
				if(character.ypos<98)
					character.ypos=98;
				
				if(leftpress && !rightpress)
				{
					xpos1+=3;
					xpos+=3;
					xpos3++;
					xpos2+=2;
					
					if(keys[VK_UP])
					{
						xpos1-=character.xvel;
						xpos-=character.xvel;
						xpos2-=character.xvel/2;
						if(character.xvel>-4)
							character.xvel-=.5;
					}
					else
						character.xvel=0;
					
					character.look=-1;
				}
				
				if(rightpress && !leftpress)
				{
					xpos-=3;
					xpos1-=3;
					xpos2-=2;
					xpos3--;
					
					if(keys[VK_UP])
					{
						xpos1-=character.xvel;
						xpos-=character.xvel;
						xpos2-=character.xvel/2;
						if(character.xvel<4)
							character.xvel+=.5;
					}
					else
						character.xvel=0;
					
					character.look=1;
				}			
			}
			SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
			while(TimerGetTime()<start+float(steps[adjust]*2.0f)) {}
			
		}
		
	}
	
	// Shutdown
	s1.updateInitFile();
	b1.KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}