示例#1
0
int
main()
{
	puts("-- 1 (should block) --");

	struct sigaction newAction;
	newAction.sa_handler = (sighandler_t)sigHandler;
	newAction.sa_mask = 0;
	newAction.sa_flags = SA_ONESHOT | SA_ONSTACK | SA_RESTART;
#if defined(__BEOS__) || defined(__ANTARES__)
	newAction.sa_userdata = (void*)kUserDataMagic;
#endif
	sigaction(SIGALRM, &newAction, NULL);

	ualarm(10000, 0);
	wait_for_key();

	puts("-- 2 (does not block, should call handler twice) --");

	newAction.sa_flags = 0;
	sigaction(SIGALRM, &newAction, NULL);

	ualarm(0, 50000);
	wait_for_key();
	wait_for_key();

	ualarm(0, 0);

	puts("-- 3 (alternate stack, should block) --");

#if defined(__BEOS__) && !defined(__ANTARES__)
	set_signal_stack(sAlternateStack, SIGSTKSZ);
#else
	stack_t newStack;
	newStack.ss_sp = sAlternateStack;
	newStack.ss_size = SIGSTKSZ;
	newStack.ss_flags = 0;
	if (sigaltstack(&newStack, NULL) != 0)
		fprintf(stderr, "sigaltstack() failed: %s\n", strerror(errno));
#endif

	newAction.sa_flags = SA_RESTART | SA_ONSTACK;
	sigaction(SIGALRM, &newAction, NULL);

	ualarm(10000, 0);
	wait_for_key();

	puts("-- end --");
	return 0;
}
示例#2
0
void gauss_main(int argc,char *argv[])
{
  dyv *dmu = mk_dyv_2(1.0,2.0);
  dym *dcov = mk_dym_22(1.0,0.0,0.0,3.0);
  dyv *dlo = mk_dyv_2(-4.0,-4.0);
  dyv *dhi = mk_dyv_2(4.0,4.0);
  dyv *mu = mk_dyv_from_args("mu",argc,argv,dmu);
  dym *cov = mk_dym_from_args("cov",argc,argv,dcov);
  dyv *lo = mk_dyv_from_args("lo",argc,argv,dlo);
  dyv *hi = mk_dyv_from_args("hi",argc,argv,dhi);

  draw_2d_gaussian(mu,cov,lo,hi);

  free_dyv(dmu);
  free_dym(dcov);
  free_dyv(dlo);
  free_dyv(dhi);
  free_dyv(mu);
  free_dym(cov);
  free_dyv(lo);
  free_dyv(hi);

  wait_for_key();
  am_malloc_report();
}
示例#3
0
static enum test_res test002_func(void)
{
    int i;
    u32 a, b, x1, x2, y1, y2;

    fill_rect(0, 0, fb_var.xres, fb_var.yres, black_pixel);
    for (i = 0; i <= Y_BLOCKS; i++)
	draw_hline(0, i*(fb_var.yres-1)/Y_BLOCKS, fb_var.xres, white_pixel);
    for (i = 0; i <= X_BLOCKS; i++)
	draw_vline(i*(fb_var.xres-1)/X_BLOCKS, 0, fb_var.yres, white_pixel);
    draw_ellipse(fb_var.xres/2, fb_var.yres/2, 3*fb_var.xres/8,
		 fb_var.yres/2-1, white_pixel);
    a = (fb_var.xres-1)/X_BLOCKS;
    b = (fb_var.yres-1)/Y_BLOCKS;
    x1 = (fb_var.xres-1)/X_BLOCKS;
    y1 = (fb_var.yres-1)/Y_BLOCKS;
    x2 = (X_BLOCKS-1)*(fb_var.xres-1)/X_BLOCKS;
    y2 = (Y_BLOCKS-1)*(fb_var.yres-1)/Y_BLOCKS;
    draw_ellipse(x1, y1, a, b, white_pixel);
    draw_ellipse(x2, y1, a, b, white_pixel);
    draw_ellipse(x1, y2, a, b, white_pixel);
    draw_ellipse(x2, y2, a, b, white_pixel);
    wait_for_key(10);
    return TEST_OK;
}
示例#4
0
void game_over(const char* reason)
{
  static const int Y_START = 1;
  static const int name_y = 8 + Y_START;

  io::clear_screen();

  int middle = sys::get_terminal_width() / 2;

  for (size_t i = 0; strlen(tomb_stone[i]); i++)
  {
    io::printf(middle, i + Y_START, io::CENTER, color_gray, "%s", tomb_stone[i]);
  }

  int death_level = 1 + current_dungeon->level - current_branch->base_level;

  io::printf(middle, name_y, io::CENTER, color_white, "%s", player.name);
  io::printf(middle, name_y + 1, io::CENTER, color_white, "Slain by: %s", reason);
  io::printf(middle, name_y + 2, io::CENTER, color_white, "In %s level %d", current_branch->name.c_str(), death_level);

  io::printf(middle, name_y + 4, io::CENTER, color_white, "%s", _get_today());
  io::printf(middle, name_y + 5, io::CENTER, color_white, "%s", _get_time());

  io::flush();
  wait_for_key("\n\r \x1B");

  exit(0);
}
示例#5
0
文件: scrn.c 项目: kalmuthu/baremetal
void video_scrollback(void)
{
    unsigned s= 9 + cpu_online;
    char msg[] = "SCROLLBACK (exit with ESC) ";
    char *m = &msg[0];
    unsigned offset_y = 0;
    unsigned x, y;
    uint8_t key;
    unsigned do_exit = 0;

    while (*m != 0) status_putch(s++, *m++);

    while (!do_exit) {
        if (offset_y > SCROLLBACK_BUF_SIZE) offset_y = SCROLLBACK_BUF_SIZE;
        for (y=0; y<23; y++) {
            for (x=0; x<80; x++) {
                textmemptr[(y+1)*80+x] = 0x0F00 | buf_scrollback[(y+offset_y)*80+x];
            }
        }

        key = wait_for_key();
        switch(key) {
            case KEY_ESC  : do_exit = 1; break;
            case KEY_UP   : if (offset_y > 0) offset_y--; break;
            case KEY_DOWN : offset_y++; break;
            case KEY_PGDOWN : offset_y+=20; break;
            case KEY_HOME : offset_y = 0; break;
            case KEY_END : offset_y = buf_y; //break;
            case KEY_PGUP   : if (offset_y > 20) offset_y-=20; else offset_y = 0; break;
        }
    }

}
示例#6
0
/*!	This works only after console_init() was called.
*/
extern "C" void
panic(const char* format, ...)
{
	const char hint[] = "*** PANIC ***";
	char buffer[512];
	va_list list;
	int length;

	platform_switch_to_text_mode();

	serial_puts(hint, sizeof(hint));
	serial_puts("\n", 1);
	//fprintf(stderr, "%s", hint);
	puts(hint);

	va_start(list, format);
	length = vsnprintf(buffer, sizeof(buffer), format, list);
	va_end(list);

	if (length >= (int)sizeof(buffer))
		length = sizeof(buffer) - 1;

	serial_puts(buffer, length);
	//fprintf(stderr, "%s", buffer);
	puts(buffer);

	puts("\nPress key to reboot.");

	clear_key_buffer();
	wait_for_key();
	platform_exit();
}
示例#7
0
int main (void)
#endif // __ANDROID__
{
  char version_string [80];

  /* We need to install a handler for SIGSEGV and friends so rowan and his
     friends can't drop a core file! */

  signal (SIGSEGV, signal_handler);
  signal (SIGBUS, signal_handler);
  signal (SIGQUIT, signal_handler);

  store_term_default ();
  set_term_raw ();

#ifndef __ANDROID__
  log_usage ();
#endif
  init_level_maps ();

  draw_frame ();
  put_screen (intro_pixmap);
  
  sprintf (version_string, "Version %s - %s %d, %d", GLIDER_VERSION, GLIDER_MONTHSTR, GLIDER_DAY, GLIDER_YEAR);
  centre_text (version_string, 12, MAX_SCR_COLS);
  
  park_cursor ();
  wait_for_key ();
  put_screen (notes_0);
  park_cursor ();
  wait_for_key ();
  put_screen (notes_1);
  park_cursor ();
  wait_for_key ();
  put_screen (notes_2);
  park_cursor ();
  wait_for_key ();

  menu ();

  ansi_Position (1, 1);
  ansi_ClearScreen ();
  set_term_default ();

  return (0); /* Exit cleanly */
}
示例#8
0
void wait_for_select (void)
{
  int KeyPressed;

  do
    {
      KeyPressed = wait_for_key ();
    }
  while ((KeyPressed != MENU_SELECT_1) && (KeyPressed != MENU_SELECT_2) && (KeyPressed != MENU_SELECT_3));
}
示例#9
0
文件: util.cpp 项目: smarmy/HellRogue
bool yesno(const std::string& prompt, bool erase)
{
  if (erase)
    erase_msg_buffer();

  append_msg_log_ex(color_light_magenta, "%s (y/n)", prompt.c_str());
  flush_turn_log();

  char key = wait_for_key("yn");
  return key == 'y';
}
示例#10
0
/* Display the message and wait for a keypress */
void message_mode(char *message)
{
	sprite_start_frame();
	sprite_group_draw2(mech_group);
	sprite_group_draw(bullet_group);
	sprite_group_draw(bomb_group);
	sprite_group_draw(effects_group);
	sprite_group_draw(foreground_group);
	sprite_group_draw(ui_group);
	text_render(sprite_global.display, 0, big_font, sprite_global.display->w / 2, sprite_global.display->h / 2, ALIGN_CENTER, ALIGN_CENTER, message);
	sprite_end_frame();
	sprite_dirty_all();
	wait_for_key();
}
示例#11
0
void menu (void)
{
  int option;
  
  while (1)
    {
      option = menu_get_input ();
      
      switch (option)
	{
	case 0:
	  game ();
	  break;
	case 3:
   	  draw_frame ();
	  put_screen (credits);
	  wait_for_key ();
	  break;
	case 4:
	  draw_frame ();
	  put_screen (help_1);
	  wait_for_key ();
	  put_screen (help_2);
	  wait_for_key ();
	  break;
	case 5:
	  return;
	default:
	  ansi_Position (1, MAX_SCR_ROWS);
	  ansi_SetAttr (ATTR_reverse);
	  ansi_printf ("This option is currently not supported");
	  ansi_SetAttr (ATTR_normal);
	  break;
	}
    }
}
示例#12
0
static enum test_res test001_func(void)
{
    int i, j;
    pixel_t pixel;
    u32 x0, y0, x1, y1;

    for (i = 1, y0 = 0; i <= Y_BLOCKS; i++, y0 = y1) {
	y1 = i*fb_var.yres/Y_BLOCKS;
	for (j = 1, x0 = 0; j <= X_BLOCKS; j++, x0 = x1) {
	    pixel = (i+j) & 1 ? white_pixel : black_pixel;
	    x1 = j*fb_var.xres/X_BLOCKS;
	    fill_rect(x0, y0, x1-x0, y1-y0, pixel);
	}
    }
    wait_for_key(10);
    return TEST_OK;
}
示例#13
0
/*!	This works only after console_init() was called.
*/
extern "C" void
panic(const char* format, ...)
{
	va_list list;

	platform_switch_to_text_mode();

	puts("*** PANIC ***");

	va_start(list, format);
	vprintf(format, list);
	va_end(list);

	puts("\nPress key to reboot.");

	clear_key_buffer();
	wait_for_key();
	platform_exit();
}
示例#14
0
/* choices is null terminated. Return the
 index of the choosen item, or -1 if escape was
 pressed.*/
int select_mode(char *header, char *choices[])
{
	int i, key, choice = 0;
	while (1)
	{
		console_clear();
		console_write(header);
		console_write("\n");
		for (i = 0; choices[i]; i++)
		{
			if (choice == i)
				console_write("*");
			else
				console_write(" ");
			console_write(choices[i]);
			console_write("\n");
		}
		console_frame();
		key = wait_for_key();
		switch (key)
		{
		case SDLK_UP:
			choice--;
			if (choice < 0)
			{
				/* seek last item */
				choice = 0;
				while (choices[choice + 1] != 0)
					choice++;
			}
			break;
		case SDLK_DOWN:
			choice++;
			if (choices[choice] == 0)
				choice = 0;
			break;
		case SDLK_ESCAPE:
			return -1;
		default:
			return choice;
		}
	}
}
示例#15
0
void test_pats()
{
  ps_usepats();
  ag_on("pattest.ps");
  ag_set_pen_color(AG_BLACK);
  ag_disc(100,100,50);
  ag_set_pen_color(AG_WHITE);
  ag_disc(100,100,40);
  ag_set_pen_color(AG_RED);
  ag_disc(100,100,30);
  ag_set_pen_color(AG_WHITE);
  ag_disc(100,100,20);
  ag_set_pen_color(AG_BLACK);
  ag_disc(100,100,10);
  ag_rectangle(50,50,150,150);
  printf("This bullseye should show up in pattest.ps, with the red part\n");
  printf("turned into a pattern instead of a color\n");
  wait_for_key();
  ag_off();
}
示例#16
0
文件: test005.c 项目: shugaoye/fbtest
static enum test_res test005_func(void)
{
    int i, j;
    pixel_t pixel;
    u32 x0, y0, x1, y1;
    int x_bits, y_bits, x_blocks, y_blocks;

    clut_init_nice();
    y_bits = idx_bits/2;
    x_bits = idx_bits-y_bits;
    x_blocks = 1<<x_bits;
    y_blocks = 1<<y_bits;
    for (i = 1, y0 = 0; i <= y_blocks; i++, y0 = y1) {
	y1 = i*fb_var.yres/y_blocks;
	for (j = 1, x0 = 0; j <= x_blocks; j++, x0 = x1) {
	    pixel = idx_pixel[(i-1)*x_blocks+(j-1)];
	    x1 = j*fb_var.xres/x_blocks;
	    fill_rect(x0, y0, x1-x0, y1-y0, pixel);
	}
    }
    wait_for_key(10);
    return TEST_OK;
}
示例#17
0
int
console_wait_for_key(void)
{
#if 0
	// XXX: do this way and remove keyboard.cpp ?
	// wait for a key
	char buffer[3];
	ssize_t bytesRead;
	do {
		bytesRead = sInput.ReadAt(NULL, 0, buffer, 3);
		if (bytesRead < 0)
			return 0;
	} while (bytesRead == 0);
#endif
	union key key = wait_for_key();

	if (key.code.ascii == 0) {
		switch (key.code.bios) {
			case BIOS_KEY_UP:
				return TEXT_CONSOLE_KEY_UP;
			case BIOS_KEY_DOWN:
				return TEXT_CONSOLE_KEY_DOWN;
			case BIOS_KEY_PAGE_UP:
				return TEXT_CONSOLE_KEY_PAGE_UP;
			case BIOS_KEY_PAGE_DOWN:
				return TEXT_CONSOLE_KEY_PAGE_DOWN;
			case BIOS_KEY_HOME:
				return TEXT_CONSOLE_KEY_HOME;
			case BIOS_KEY_END:
				return TEXT_CONSOLE_KEY_END;
			default:
				return 0;
		}
	} else
		return key.code.ascii;
}
示例#18
0
文件: main.c 项目: andreiw/iQUIK
static quik_err_t
get_params(char **kernel,
           char **initrd,
           char **params,
           env_dev_t *cur_dev)
{
   char *p;
   char *q;
   int n;
   char *buf;
   char *endp;
   key_t lastkey;
   char *label = NULL;
   int timeout = DEFAULT_TIMEOUT;

   if ((bi->flags & TRIED_AUTO) == 0) {
      bi->flags ^= TRIED_AUTO;
      *params = bi->bootargs;
      *kernel = *params;

      word_split(kernel, params);
      if (!*kernel) {
         *kernel = cfg_get_default();

         /*
          * Timeout only makes sense
          * if we don't have an image name already
          * passed.
          */
         if ((bi->flags & CONFIG_VALID) &&
             (q = cfg_get_strg(0, "timeout")) != 0 && *q != 0) {
           timeout = strtol(q, NULL, 0);
         }
      } else {

         /*
          * We have something, boot immediately.
          */
         timeout = 0;
      }
   }

   printk(PROMPT);
   lastkey = KEY_NONE;
   if (timeout != -1) {
      lastkey = wait_for_key(timeout, '\n');
   }

   if (lastkey == '\n') {
      printk("%s", *kernel);
      if (*params) {
         printk(" %s", *params);
      }

      printk("\n");
   } else {
      *kernel = NULL;

      buf = cmd_edit(maintabfunc, lastkey);
      if (buf == NULL) {
         return ERR_NOT_READY;
      }

      *kernel = buf;
      word_split(kernel, params);
   }

   if (bi->flags & CONFIG_VALID) {
      *initrd = cfg_get_strg(0, "initrd");
      p = cfg_get_strg(*kernel, "image");
      if (p && *p) {
         label = *kernel;
         *kernel = p;

         p = cfg_get_strg(label, "device");
         if (p) {
            cur_dev->device = p;
         }

         p = cfg_get_strg(label, "partition");
         if (p) {
            n = strtol(p, &endp, 10);
            if (endp != p && *endp == 0) {
               env_dev_set_part(cur_dev, n);
            }
         }

         p = cfg_get_strg(label, "initrd");
         if (p) {
            *initrd = p;
         }

         if (cfg_get_strg(label, "old-kernel")) {
            bi->flags |= BOOT_PRE_2_4;
         } else {
            bi->flags &= ~BOOT_PRE_2_4;
         }

         *params = make_params(label, *params);
         if (*params == NULL) {
            return ERR_NO_MEM;
         }
      }
   }

   if (*kernel == NULL) {
      printk("<TAB> for list of bootable images, or !help\n");
      return ERR_NOT_READY;
   }

   /*
    * If we manually entered kernel path, the initrd could
    * be following in the param list...
    */
   if (label == NULL) {
      *params = chomp(*params);

      if (memcmp(*params, "-- ", 3) != 0) {
         *initrd = *params;
         word_split(initrd, params);
      } else {

         /*
          * No initrd, just kernel args.
          */
         *params = *params + 3;
      }
   }

   return ERR_NONE;
}
示例#19
0
void glk_main(void)
{
    winid_t win_a = NULL, win_b = NULL, win_c = NULL, win_d = NULL;
	
	fprintf(stderr, "TEST CASES FROM GLK SPEC\n\n"
			"(Press a key in window A to continue each time)\n\n"
			"Say you do two splits, each a 50-50 percentage split. You start\n"
			"with the original window A, and split that into A and B; then\n"
			"you split B into B and C.\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_b, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	
	wait_for_key(win_a);
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "Or, you could split A into A and B, and then split A\n"
			"again into A and C.\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	
	wait_for_key(win_a);
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "Here are more ways to perform the first example; all of\n"
			"them have the same tree structure, but look different on the\n"
			"screen. Here, we turn the second split (B into B/C) upside down;\n"
			"we put the new window (C) above the old window (B).\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_b, winmethod_Proportional | winmethod_Above,
							50, wintype_TextBuffer, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	
	wait_for_key(win_a);
	glk_window_close(glk_window_get_root(), NULL);
			
	fprintf(stderr, "Here, we mess with the percentages. The first split (A\n"
			"into A/B) is a 25-75 split, which makes B three times the size\n"
			"of A. The second (B into B/C) is a 33-66 split, which makes C\n"
			"twice the size of B. This looks rather like the second example,\n"
			"but has a different internal structure.\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							75, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_b, winmethod_Proportional | winmethod_Below,
							67, wintype_TextBuffer, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	
	wait_for_key(win_a);
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "Here, the second split (B into B/C) is vertical instead\n"
			"of horizontal, with the new window (C) on the left of the old\n"
			"one.\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_b, winmethod_Proportional | winmethod_Left,
							50, wintype_TextBuffer, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	
	wait_for_key(win_a);
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "In the following two-split process, you can see that\n"
			"when a window is split, it is replaced by a new pair window, and\n"
			"moves down to become one of its two children.\n\n");
	
	if(!(win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A");
	wait_for_key(win_a);
	
	if(!(win_b = glk_window_open(win_a, 
								 winmethod_Proportional | winmethod_Below,
								 50, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	wait_for_key(win_a);
	
	if(!(win_c = glk_window_open(win_b, winmethod_Proportional | winmethod_Left,
								 50, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	wait_for_key(win_a);
	
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "What happens when there is a conflict? The rules are\n"
			"simple. Size control always flows down the tree, and the player\n"
			"is at the top. Let's bring out an example: first we split A into\n"
			"A and B, with a 50%% proportional split. Then we split A into A\n"
			"and C, with C above, being a text grid window, and C gets a\n"
			"fixed size of two rows (as measured in its own font size). A\n"
			"gets whatever remains of the 50%% it had before.\n\n");
	
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below,
							50, wintype_TextBuffer, 0);
	win_c = glk_window_open(win_a, winmethod_Fixed | winmethod_Above,
							2, wintype_TextGrid, 0);
	if(!win_a || !win_b || !win_c)
		return;
	center_text(win_a, "A");
	center_text(win_b, "B: 50%");
	print_two_rows(win_c);
	wait_for_key(win_a);
	
	fprintf(stderr, "(Stage 1) Now the player stretches the window\n"
			"vertically.\n\n");
	
	wait_for_key(win_a);
	
	fprintf(stderr, "(Stage 2) Then the user maliciously starts squeezing the\n"
			"window down, in stages.\n\n");
	
	center_text(win_a, "A");
	center_text(win_b, "B: 50%");
	print_two_rows(win_c);
	wait_for_key(win_a);
	
	fprintf(stderr, "(Stage 3) The logic remains the same. At stage 3,\n"
			"there's no room left for A, so it winds up with zero height.\n"
			"Nothing displayed in A will be visible.\n\n");
	
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	wait_for_key(win_a);
	
	fprintf(stderr, "(Stage 4) At stage 4, there isn't even room in the upper\n"
			"50%% to give C its two rows; so it only gets one.\n\n");
	
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	wait_for_key(win_a);
	
	fprintf(stderr, "(Stage 5) Finally, C is squashed out of existence as\n"
			"well.\n\n");
	
	center_text(win_a, "A");
	center_text(win_b, "B");
	wait_for_key(win_a);
	
	glk_window_close(glk_window_get_root(), NULL);
	
	fprintf(stderr, "What happens when you split a fixed-size window? The\n"
			"resulting pair window retains the same size constraint as the\n"
			"original window that was split. The key window for the original\n"
			"split is still the key window for that split, even though it's\n"
			"now a grandchild instead of a child.\n\n");
	
	if(!(win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A");
	wait_for_key(win_a);
	
	fprintf(stderr, "After the first split, the new pair window (O1, which\n"
			"covers the whole screen) knows that its first child (A) is above\n"
			"the second, and gets 50%% of its own area. (A is the key window\n"
			"for this split, but a proportional split doesn't care about key\n"
			"windows.)\n\n");
	
	if(!(win_b = glk_window_open(win_a, 
								 winmethod_Proportional | winmethod_Below,
								 50, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A: 50%");
	center_text(win_b, "B");
	wait_for_key(win_a);
	
	fprintf(stderr, "After the second split, all this remains true; O1 knows\n"
			"that its first child gets 50%% of its space, and A is O1's key\n"
			"window. But now O1's first child is O2 instead of A. The newer\n"
			"pair window (O2) knows that its first child (C) is above the\n"
			"second, and gets a fixed size of two rows. (As measured in C's\n"
			"font, because C is O2's key window.)\n\n");
	
	if(!(win_c = glk_window_open(win_a, winmethod_Fixed | winmethod_Above, 2,
								 wintype_TextGrid, 0)))
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	print_two_rows(win_c);
	wait_for_key(win_a);
	
	fprintf(stderr, "If we split C, now, the resulting pair will still be two\n"
			"C-font rows high -- that is, tall enough for two lines of\n"
			"whatever font C displays. For the sake of example, we'll do this\n"
			"vertically.\n\n");
	
	if(!(win_d = glk_window_open(win_c, 
								 winmethod_Proportional | winmethod_Right,
								 50, wintype_TextBuffer, 0)))
		return;
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "When you close a window (and it is not the root window),\n"
			"the other window in its pair takes over all the freed-up area.\n"
			"Let's close D, in the current example:\n\n");
	
	glk_window_close(win_d, NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_c, "C");
	wait_for_key(win_a);
	
	fprintf(stderr, "But what if we had closed C instead of D? We would have\n"
			"gotten this:\n\n");
	
	glk_window_close(glk_window_get_root(), NULL);
	win_a = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
	win_b = glk_window_open(win_a, winmethod_Proportional | winmethod_Below, 50,
							wintype_TextBuffer, 0);
	win_c = glk_window_open(win_a, winmethod_Fixed | winmethod_Above, 2,
							wintype_TextGrid, 0);
	win_d = glk_window_open(win_c, winmethod_Proportional | winmethod_Right, 50,
							wintype_TextBuffer, 0);
	glk_window_close(win_c, NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "Consider the example above, where D had collapsed to\n"
			"zero height. Say D was a text buffer window. You could make a\n"
			"more useful layout:\n\n");
	winid_t o2 = glk_window_get_parent(win_d);
	glk_window_set_arrangement(o2, winmethod_Above | winmethod_Fixed, 3, win_d);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "If you later wanted to expand D to five rows:\n\n");
	glk_window_set_arrangement(o2, winmethod_Above | winmethod_Fixed, 5, NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "This changes the constraint to be on the lower child of\n"
			"O2, which is A. The key window is still D; so A would then be\n"
			"three rows high as measured in D's font, and D would get the\n"
			"rest of O2's space. That may not be what you want.\n\n");
	glk_window_set_arrangement(o2, winmethod_Below | winmethod_Fixed, 3, NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "To set A to be three rows high as measured in A's font,\n"
			"you would do:\n\n");
	glk_window_set_arrangement(o2, winmethod_Below | winmethod_Fixed, 3, win_a);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "Or you could change O2 to a proportional split:\n\n");
	glk_window_set_arrangement(o2, winmethod_Below | winmethod_Proportional, 30,
							   NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	fprintf(stderr, "Or:\n\n");
	glk_window_set_arrangement(o2, winmethod_Above | winmethod_Proportional, 70,
							   NULL);
	center_text(win_a, "A");
	center_text(win_b, "B");
	center_text(win_d, "D");
	wait_for_key(win_a);
	
	glk_window_close(win_d, NULL);
	glk_window_close(win_b, NULL);
	glk_window_clear(win_a);
	glk_set_window(win_a);
	glk_put_string("That's all, folks...");
}
示例#20
0
int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
{
    if(multirom_init_fb(s->rotation) < 0)
        return UI_EXIT_BOOT_ROM;

    fb_freeze(1);

    mrom_status = s;

    exit_ui_code = -1;
    selected_rom = NULL;
    active_msgbox = NULL;

    multirom_ui_setup_colors(s->colors, &CLR_PRIMARY, &CLR_SECONDARY);
    themes_info = multirom_ui_init_themes();
    if((cur_theme = multirom_ui_select_theme(themes_info, fb_width, fb_height)) == NULL)
    {
        fb_freeze(0);

        ERROR("Couldn't find theme for resolution %dx%d!\n", fb_width, fb_height);
        fb_add_text(0, 0, WHITE, SIZE_SMALL, "Couldn't find theme for resolution %dx%d!\nPress POWER to reboot.", fb_width, fb_height);
        fb_draw();
        fb_clear();
        fb_close();

        start_input_thread();
        while(wait_for_key() != KEY_POWER);
        stop_input_thread();
        return UI_EXIT_REBOOT;
    }

    workers_start();

    multirom_ui_init_header();
    multirom_ui_switch(TAB_INTERNAL);

    add_touch_handler(&multirom_ui_touch_handler, NULL);
    start_input_thread();
    keyaction_enable(1);
    keyaction_set_destroy_msgbox_handle(multirom_ui_destroy_msgbox);

    multirom_set_brightness(s->brightness);

    fb_freeze(0);

    if(s->auto_boot_rom && s->auto_boot_seconds > 0)
        multirom_ui_auto_boot();
    else
        fb_draw();

    while(1)
    {
        pthread_mutex_lock(&exit_code_mutex);
        if(exit_ui_code != -1)
        {
            pthread_mutex_unlock(&exit_code_mutex);
            break;
        }

        if(loop_act & LOOP_UPDATE_USB)
        {
            multirom_find_usb_roms(mrom_status);
            if(themes_info->data->selected_tab == TAB_USB)
                multirom_ui_tab_rom_update_usb(themes_info->data->tab_data);
            loop_act &= ~(LOOP_UPDATE_USB);
        }

        if(loop_act & LOOP_START_PONG)
        {
            loop_act &= ~(LOOP_START_PONG);
            keyaction_enable(0);
            input_push_context();
            fb_push_context();

            pong();

            fb_pop_context();
            input_pop_context();
            keyaction_enable(1);
        }

        if(loop_act & LOOP_CHANGE_CLR)
        {
            fb_freeze(1);

            multirom_ui_setup_colors(s->colors, &CLR_PRIMARY, &CLR_SECONDARY);

            // force redraw tab
            int tab = themes_info->data->selected_tab;
            themes_info->data->selected_tab = -1;

            multirom_ui_destroy_tab(tab);
            multirom_ui_switch(tab);

            fb_freeze(0);
            fb_draw();

            loop_act &= ~(LOOP_CHANGE_CLR);
        }

        pthread_mutex_unlock(&exit_code_mutex);

        usleep(100000);
    }

    keyaction_enable(0);
    keyaction_clear();

    rm_touch_handler(&multirom_ui_touch_handler, NULL);

    fb_create_msgbox(500*DPI_MUL, 250*DPI_MUL, CLR_PRIMARY);

    switch(exit_ui_code)
    {
        case UI_EXIT_BOOT_ROM:
            *to_boot = selected_rom;
            fb_msgbox_add_text(-1, 40*DPI_MUL, SIZE_BIG, "Booting ROM...");
            fb_msgbox_add_text(-1, -1, SIZE_NORMAL, selected_rom->name);
            break;
        case UI_EXIT_REBOOT:
        case UI_EXIT_REBOOT_RECOVERY:
        case UI_EXIT_REBOOT_BOOTLOADER:
            fb_msgbox_add_text(-1, -1, SIZE_BIG, "Rebooting...");
            break;
        case UI_EXIT_SHUTDOWN:
            fb_msgbox_add_text(-1, -1, SIZE_BIG, "Shutting down...");
            break;
    }

    fb_draw();
    fb_freeze(1);

    cur_theme->destroy(themes_info->data);

    int i;
    for(i = 0; i < TAB_COUNT; ++i)
    {
        button_destroy(themes_info->data->tab_btns[i]);
        themes_info->data->tab_btns[i] = NULL;
    }

    stop_input_thread();

    multirom_ui_destroy_tab(themes_info->data->selected_tab);
    multirom_ui_free_themes(themes_info);
    themes_info = NULL;

    workers_stop();

    fb_clear();
#if MR_DEVICE_HOOKS >= 2
    mrom_hook_before_fb_close();
#endif
    fb_close();
    return exit_ui_code;
}
示例#21
0
void item_list::execute()
{
  const std::string keys = "\x1B \nabcdefghijklmnopqrstuvwxyz<>?";
  char key = 0;
  bool done = false;

  while (!done)
  {
    print();
    key = wait_for_key(keys);

    if (char_in(key, "\x1B \n"))
    {
      if (m_examine_mode)
      {
        m_examine_mode = false;
      }
      else
      {
        break;
      }
    }

    if (key == '<')
    {
      if (m_page > 0)
      {
        m_page--;
      }
    }
    else if (key == '>')
    {
      if (m_page == 0 && m_items.size() > PAGE_SIZE)
      {
        m_page++;
      }
    }
    else if (key == '?')
    {
      m_examine_mode = !m_examine_mode;
    }
    else if (valid_entry(key))
    {
      if (!m_examine_mode)
      {
        done = handle_item(get_entry(key).item);
      }
      else
      {
        item_t* item_to_describe = get_entry(key).item;
        describe(item_to_describe);
      }
    }
  }

  if (m_action == ZAP)
  {
    if (key == '\x1B' || key == ' ' || key == '\n')
    {
      // Pop wand selection state.
      statestack_pop();
    }
  }

  // Always cancel if escape;
  if (key == '\x1B')
  {
    m_chosen_items.clear();
    return;
  }

  if (m_action == DROP)
  {
    handle_dropped();
  }
}
示例#22
0
void screen_main(int argc,char *argv[])
{
  int i;
  printf("Will do ag_window_shape(384,384);\n");
  wait_for_key();
  ag_window_shape(384,384);

  printf("Will do ag_on(test.ps);\n");
  wait_for_key();
  ag_on("test.ps");

  printf("Will do ag_line(10.0,10.0,256.0,502.0);\n");
  wait_for_key();
  ag_line(10.0,10.0,256.0,502.0);

  printf("Will do ag_off();\n");
  wait_for_key();
  ag_off();

  printf("Will do ag_on("");\n");
  wait_for_key();
  ag_on("");

  printf("Will do ag_line(10.0,10.0,502.0,256.0);\n");
  wait_for_key();
  ag_line(10.0,10.0,502.0,256.0);

  printf("Will do ag_screen_shape(600.0,600.0);\n");
  wait_for_key();
  ag_window_shape(600.0,600.0);

  printf("Will do ag_line(10.0,10.0,502.0,256.0);\n");
  wait_for_key();
  ag_line(10.0,10.0,502.0,256.0);

  printf("Will do ag_off();\n");
  wait_for_key();
  ag_off();

  printf("Will do ag_on(test2.ps);\n");
  wait_for_key();
  ag_on("test2.ps");

  printf("Will do ag_line(10.0,10.0,256.0,502.0);\n");
  wait_for_key();
  ag_line(10.0,10.0,256.0,502.0);

  for ( i = 2 ; i < 25 ; i++ )
  {
    if ( i == 12 ) ag_set_pen_color(AG_RED);
    ag_pixel((double)i,(double)(i*i));
  }

  printf("Will do ag_off();\n");
  wait_for_key();
  ag_off();

  printf("Done\n");
  wait_for_key();
}