Beispiel #1
0
void
prompt_to_load_file()
{
	char msg[] = "Please select the map file you wish to load";
	char path[FILENAME_MAX * 6] = { "\0" };
	int result;

	mouse_callback = NULL;
	result = file_select_ex(msg, path, "txt", sizeof(path), 0, 0);
	if (!result)
	{
		if (nodelist != NULL && vector_len((vector_t*)nodelist) > 0)
			return;
		allegro_message("You did not select a file to load: there's nothing for the program to do.  Exiting.");
		exit(0);
	}

	if (debugging)
		fprintf(stderr, "%s\n", path);
	nodelist = load_file(path);

	render_image(screen);
	render_image(backbuffer);
	render_info(screen);
	render_info(backbuffer);
	strncpy(last_file, path, sizeof(last_file));
	mouse_callback = mouse_cb;
}
static int
load_proc(void)
{
	char buffer[256], *p;
	BITMAP *bmp;
	PALETTE palette;

	if (file_select_ex("Load image", last_path, "bmp;pcx;lbm;tga;jpg;jpeg", 1024, (SCREEN_W * 2) / 3, (SCREEN_H * 2) / 3)) {
		bmp = load_jpg_ex(last_path, palette, progress_cb);
		if (!bmp)
			bmp = load_bitmap(last_path, palette);
		settings_dialog[PREVIEW].dp = bmp;
		if (!bmp) {
			sprintf(buffer, "Error loading image (JPG error code: %d)", jpgalleg_error);
			alert("", buffer, "", "Ok", NULL, 0, 0);
			return 0;
		}
		for (p = last_path + strlen(last_path); (p >= last_path) && (*p != '/') && (*p != '\\'); p--)
			;
		*(p + 1) = '\0';
		sx = sy = old_sx = old_sy = 0;
		set_palette(palette);
		popup_menu[1].flags = 0;
	}
	return 0;
}
Beispiel #3
0
/* handle the save command */
int saver()
{
   char buf[FILENAME_LENGTH];

   strcpy(buf, config_file);

   if (file_select_ex("Save Keyboard Config", buf, "CFG", sizeof(buf), 0, 0)) {
      if ((stricmp(config_file, buf) != 0) && (exists(buf))) {
	 if (alert("Overwrite existing file?", NULL, NULL, "Yes", "Cancel", 'y', 27) != 1)
	    return D_REDRAW;
      }

      strlwr(buf);
      strcpy(config_file, buf);

      push_config_state();
      set_config_file(buf);

      set_config_string(NULL, "keyboard_name", keyboard_name);

      set_config_int("key_escape", "accent1", _key_accent1);
      set_config_int("key_escape", "accent2", _key_accent2);
      set_config_int("key_escape", "accent3", _key_accent3);
      set_config_int("key_escape", "accent4", _key_accent4);
      set_config_int("key_escape", "accent1_flag", _key_accent1_flag);
      set_config_int("key_escape", "accent2_flag", _key_accent2_flag);
      set_config_int("key_escape", "accent3_flag", _key_accent3_flag);
      set_config_int("key_escape", "accent4_flag", _key_accent4_flag);

      save_table(_key_ascii_table,               orig_key_ascii_table,               "key_ascii");
      save_table(_key_capslock_table,            orig_key_capslock_table,            "key_capslock");
      save_table(_key_shift_table,               orig_key_shift_table,               "key_shift");
      save_table(_key_control_table,             orig_key_control_table,             "key_control");

      if (split_altgr) {
         save_table(_key_altgr_lower_table,      orig_key_altgr_lower_table,         "key_altgr_lower");
         save_table(_key_altgr_upper_table,      orig_key_altgr_upper_table,         "key_altgr_upper");
      }
      else {
         save_table(_key_altgr_lower_table,      orig_key_altgr_lower_table,         "key_altgr");
      }

      save_table(_key_accent1_lower_table,       orig_key_accent1_lower_table,       "key_accent1_lower");
      save_table(_key_accent1_upper_table,       orig_key_accent1_upper_table,       "key_accent1_upper");
      save_table(_key_accent2_lower_table,       orig_key_accent2_lower_table,       "key_accent2_lower");
      save_table(_key_accent2_upper_table,       orig_key_accent2_upper_table,       "key_accent2_upper");
      save_table(_key_accent3_lower_table,       orig_key_accent3_lower_table,       "key_accent3_lower");
      save_table(_key_accent3_upper_table,       orig_key_accent3_upper_table,       "key_accent3_upper");
      save_table(_key_accent4_lower_table,       orig_key_accent4_lower_table,       "key_accent4_lower");
      save_table(_key_accent4_upper_table,       orig_key_accent4_upper_table,       "key_accent4_upper");

      pop_config_state();
   }

   return D_REDRAW;
}
Beispiel #4
0
int gui_vdfs_root() {
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        strncpy(tempname, vdfs_get_root(), sizeof(tempname));
        memcpy(tempname, discfns[1], 260);
        ret = file_select_ex("Please select VDFS root directory", tempname, NULL, 260, xsize, ysize);
        if (ret)
            vdfs_set_root(tempname);
        gui_update();
        return D_CLOSE;
}
Beispiel #5
0
int gui_scrshot()
{
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        tempname[0] = 0;
        ret = file_select_ex("Please enter filename", tempname, "BMP", 260, xsize, ysize);
        if (ret)
        {
                memcpy(vid_scrshotname, tempname, 260);
                printf("Save scrshot\n");
                vid_savescrshot = 2;
        }
        return D_CLOSE;
}
Beispiel #6
0
int gui_loadss()
{
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        memcpy(tempname, discfns[0], 260);
        ret = file_select_ex("Please choose a save state", tempname, "SNP", 260, xsize, ysize);
        if (ret)
        {
                strcpy(savestate_name, tempname);
                savestate_load();
        }
        gui_update();
        return D_CLOSE;
}
Beispiel #7
0
int gui_loadt()
{
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        memcpy(tempname, tape_fn, 260);
        ret=file_select_ex("Please choose a tape image", tempname, "UEF;CSW", 260, xsize, ysize);
        if (ret)
        {
                tape_close();
                memcpy(tape_fn, tempname, 260);
                tape_load(tape_fn);
                tape_loaded = 1;
        }
        return D_CLOSE;
}
Beispiel #8
0
static int gui_load_drive(int drive, const char *prompt)
{
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        memcpy(tempname, discfns[drive], 260);
        ret = file_select_ex(prompt, tempname, "SSD;DSD;IMG;ADF;ADL;FDI", 260, xsize, ysize);
        if (ret)
        {
                disc_close(drive);
                memcpy(discfns[drive], tempname, 260);
                disc_load(drive, discfns[drive]);
                if (defaultwriteprot)
                        writeprot[drive] = 1;
        }
        gui_update();
        return ret;
}
Beispiel #9
0
int gui_savess()
{
        char tempname[260];
        int ret;
        int xsize = windx - 32, ysize = windy - 16;
        if (curtube != -1)
        {
                alert(NULL, "Second processor save states not supported yet.", NULL, "&OK", NULL, 0, 0);
                return D_CLOSE;
        }
        memcpy(tempname, discfns[0], 260);
        ret = file_select_ex("Please choose a save state", tempname, "SNP", 260, xsize, ysize);
        if (ret)
        {
                strcpy(savestate_name, tempname);
                savestate_save();
        }
        gui_update();
        return D_CLOSE;
}
static int
save_proc(void)
{
	char filename[1024];
	char buffer[256], *p;
	BITMAP *bmp = NULL;
	int quality = 0, flags = 0;

	if (file_select_ex("Save as JPG", last_path, "jpg", 1024, (SCREEN_W * 2) / 3, (SCREEN_H * 2) / 3)) {
		strcpy(filename, last_path);
		for (p = last_path + strlen(last_path); (p >= last_path) && (*p != '/') && (*p != '\\'); p--)
			;
		*(p + 1) = '\0';
		set_dialog_color(settings_dialog, gui_fg_color, gui_bg_color);
		centre_dialog(settings_dialog);
		if (popup_dialog(settings_dialog, -1) < 0)
			return 0;
		quality = settings_dialog[QUALITY_SLIDER].d2 + 1;
		if (settings_dialog[SS_444_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_444;
		if (settings_dialog[SS_422_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_422;
		if (settings_dialog[SS_411_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_411;
		if (settings_dialog[GREYSCALE_CHECK].flags & D_SELECTED)
			flags |= JPG_GREYSCALE;
		if (settings_dialog[OPTIMIZE_CHECK].flags & D_SELECTED)
			flags |= JPG_OPTIMIZE;
		bmp = settings_dialog[PREVIEW].dp;

		if (save_jpg_ex(filename, bmp, NULL, quality, flags, progress_cb)) {
			sprintf(buffer, "Error saving JPG image (error code %d)", jpgalleg_error);
			alert("", buffer, "", "Ok", NULL, 0, 0);
		}
	}
	return 0;
}
Beispiel #11
0
void loadLayoutFromFile()
{
  if(file_select_ex("Please select layout file to play:", path, "lyt",
      PATH_LENGTH-1, OLD_FILESEL_WIDTH, OLD_FILESEL_HEIGHT))
  {
    FILE *file = fopen(path, "r");

    if(file)
    {
      Layout data;

      if(fread(&data, sizeof(Layout), 1, file))
      {
	int x, y, z;

	for(x = 0; x < 54; x++)
	  if(data.title[x] == 0)
	    break;
	  else if(data.title[x] < 0x20 || data.title[x] > 0x7e)
	    goto corrupt;
	for(; x < 55; x++)
	  if(data.title[x] != 0)
	    goto corrupt;

	z = 144;
	for(x = 16; x--;)
	for(y =  9; y--;)
	  if(data.board[x][y] > 3)
	    goto corrupt;
	  else
	    z--;

	if(data.complete != 1)
	{
	  alert("Layout file is incomplete:", NULL, path, "Okay", NULL, 0, 0);
	  goto close;
	}

	if(z)
	  goto corrupt;

	for(x = 16; x--;)
	for(y =  9; y--;)
	{
	  for(z = 3; z > data.board[x][y];)
	    board[x][y][--z].value = EMPTY;
	  while(z)
	    board[x][y][--z].value = BLANK;
	}

	shuffle();
      }
      else
      {
corrupt:
	alert("Layout file invalid or corrupt:", NULL, path, "Okay", NULL, 0, 0);
      }

close:
      fclose(file);
    }
    else
      alert("Could not open layout file:", NULL, path, "Okay", NULL, 0, 0);
  }
}
Beispiel #12
0
int main(int argc, char *argv[])
{
  {
    int i;

    if((argc - 1) % 2)
      goto help;

    for(i = 1; i < argc - 1; i += 2)
      if(!editing && (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--edit")))
	editing = argv[i+1];
      else if(!layout_title[0] && (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--title")))
      {
	bzero(layout_title, 55);
	strncpy(layout_title, argv[i+1], 54);
      }
      else
      {
help:
	printf("usage: mahjong [--edit <layout> [--title <layout title>]]\n");
	return 0;
      }
  }

  srand(time(NULL));
  allegro_init();

  {
    int x, y, z;
    for(x = 16; x--;)
    for(y =  9; y--;)
    for(z =  3; z--;)
      pieceInit(board[x][y][z], x, y, z);
  }

  set_color_depth(SCREEN_DEPTH);

  if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,
      SCREEN_WIDTH,   SCREEN_HEIGHT,
      SCREEN_WIDTH*2, SCREEN_HEIGHT) < 0)
  {
    fprintf(stderr, "fatal: %s\n", allegro_error);
    exit(1);
  }

#ifdef ALLEGRO_WINDOWS
  set_display_switch_callback(SWITCH_IN, update);
#endif

  left_view =
    create_sub_bitmap(screen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  right_view =
    create_sub_bitmap(screen, SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

  // init colors
    BACKGROUND_COLOR = makecol32(0x2F, 0x5F, 0x2F); // soft green
      SELECTED_COLOR = makecol32(0x00, 0xDF, 0x00); // green
  OLD_SELECTED_COLOR = makecol32(0x00, 0xBF, 0xBF); // cyan

  // load data
  {
    DATAFILE *data = load_datafile("#");
    new_game   = data[NEW_GAME_BMP].dat;
    undo       = data[UNDO_BMP].dat;
    help       = data[HELP_BMP].dat;
    quit       = data[QUIT_BMP].dat;
    tile       = data[TILE_BMP].dat;
    number[ 0] = data[BLACK1_BMP].dat;
    number[ 2] = data[BLACK2_BMP].dat;
    number[ 4] = data[BLACK3_BMP].dat;
    number[ 6] = data[BLACK4_BMP].dat;
    number[ 8] = data[BLACK5_BMP].dat;
    number[10] = data[BLACK6_BMP].dat;
    number[12] = data[BLACK7_BMP].dat;
    number[14] = data[BLACK8_BMP].dat;
    number[16] = data[BLACK9_BMP].dat;
    number[ 1] = data[RED1_BMP].dat;
    number[ 3] = data[RED2_BMP].dat;
    number[ 5] = data[RED3_BMP].dat;
    number[ 7] = data[RED4_BMP].dat;
    number[ 9] = data[RED5_BMP].dat;
    number[11] = data[RED6_BMP].dat;
    number[13] = data[RED7_BMP].dat;
    number[15] = data[RED8_BMP].dat;
    number[17] = data[RED9_BMP].dat;
    suit[0]    = data[SPADE_BMP].dat;
    suit[1]    = data[CLUB_BMP].dat;
    suit[2]    = data[DIAMOND_BMP].dat;
    suit[3]    = data[HEART_BMP].dat;
    layouts[0] = data[BLOCK_LYT].dat;
    layouts[1] = data[FLAT_LYT].dat;
    layouts[2] = data[FROGGER_LYT].dat;
    layouts[3] = data[PRECIOUS_LYT].dat;
    layouts[4] = data[PTRAD_LYT].dat;
    layouts[5] = data[PYRAMID_LYT].dat;
    layouts[6] = data[STEPS_LYT].dat;
    layouts[7] = data[THETA_LYT].dat;
  }

  scroll_screen(SCREEN_WIDTH, 0);
  current_view = right_view;

  install_timer();
  install_mouse();
  install_keyboard();
  show_mouse(current_view);

  text_mode(BACKGROUND_COLOR);

  if(!editing)
  {
    defaultLayout();

    if(alert("Our Own Version of Mahjong Solitaire, v0.1.4", NULL,
	     "Copyright (c) 2001 Eric Mulvaney, Michelle Bondy",
	     "Play", "Edit", 0, 0) == 2
	&& file_select_ex("Please select layout file to edit:", path, "lyt",
	    PATH_LENGTH-1, OLD_FILESEL_WIDTH, OLD_FILESEL_HEIGHT))
    {
      int x, y, z;

      editing = path;

      for(x = 16; x--;)
      for(y =  9; y--;)
      for(z =  3; z--;)
	board[x][y][z].value = EMPTY;
    }
  }

  mouse_callback = editing ? mouse_handler_for_editing : mouse_handler;

  if(editing)
  {
    Layout data;
    FILE *file = fopen(editing, "r");

    if(file)
    {
      if(fread(&data, sizeof(Layout), 1, file))
      {
	int x, y, z;

	if(!layout_title[0])
	  memcpy(layout_title, data.title, 55);

	for(x = 16; x--;)
	for(y =  9; y--;)
	for(z = (data.board[x][y] > 3) ? 3 : data.board[x][y]; z--;)
	{
	  board[x][y][z].value = BLANK;
	  if(!--n_pieces_left)
	    goto skip;
	}
      }
skip:
      fclose(file);
    }

    update();
  }

  click_ready = 0;
  while(1) // game loop
  {
    if(click_ready)
    {
      int x = click_x - (BOARD_XOFF - 2 * EDGE_WIDTH );
      int y = click_y - (BOARD_YOFF - 2 * EDGE_HEIGHT);
      int z;

      for(z = 3; x > 0 && y > 0 && z--; x -= EDGE_WIDTH, y -= EDGE_HEIGHT)
      {
	int i = x / FACE_WIDTH;
	int j = y / FACE_HEIGHT;

	if(i >= 16 || j >= 9)
	  continue;

	if(editing)
	{
	  if(click_ready == 1 && board[i][j][z].value == EMPTY)
	  {
	    if((z == 0 || board[i][j][z-1].value != EMPTY) && n_pieces_left)
	    {
	      n_pieces_left--;
	      board[i][j][z].value = BLANK;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	  else if(click_ready == 2 && board[i][j][z].value != EMPTY)
	  {
	    if(z == 2 || board[i][j][z+1].value == EMPTY)
	    {
	      board[i][j][z].value = EMPTY;
	      n_pieces_left++;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	}
	else if(selectPiece(&board[i][j][z]))
	{
	  if(!n_pairs_remaining)
	  {
	    if(current_view != left_view)
	      update();

	    if(alert("Congratulations!	You won!",
		     "Play another?",
		     NULL, "Yes", "No", 0, 0) == 1)
	      newGame();
	    else
	      return 0;
	  }

	  goto event_handled;
	}
      }

      if(click_y < BUTTON_YOFF + BUTTON_HEIGHT && click_y > BUTTON_YOFF)
      {
	if(editing)
	{
	  if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  {
	    if(n_pieces_left == 144)
	      goto event_handled;

	    if(current_view != left_view)
	      update();

	    if(alert("Are you sure you want to clear the current Layout?",
		     NULL, NULL, "Yes", "No", 0, 0) == 1)
	    {
	      int x, y, z;
	      for(x = 16; x--;)
	      for(y =  9; y--;)
	      for(z =  3; z--;)
		board[x][y][z].value = EMPTY;
	      n_pieces_left = 144;
	      update();
	    }
	  }
	  else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	  {
	    int ync;

	    if(current_view != left_view)
	      update();

	    if(n_pieces_left)
	      ync = alert3("WARNING: Layout is incomplete.",
			   NULL,
			   "Do you wish to save before exiting?",
			   "Yes", "No", "Cancel", 0, 0, 0);
	    else
	      ync = alert3("Do you wish to save before exiting?",
		    NULL, NULL, "Yes", "No", "Cancel", 0, 0, 0);

	    if(ync == 2)
	      return 0;
	    else if(ync == 1)
	    {
	      Layout data;
	      FILE *file;

	      memcpy(data.title, layout_title, 55);

	      data.complete = (n_pieces_left) ? 0 : 1;

	      if((file = fopen(editing, "w")))
	      {
		for(x = 16; x--;)
		for(y =  9; y--;)
		{
		  if	 (board[x][y][2].value == BLANK) data.board[x][y] = 3;
		  else if(board[x][y][1].value == BLANK) data.board[x][y] = 2;
		  else if(board[x][y][0].value == BLANK) data.board[x][y] = 1;
		  else					 data.board[x][y] = 0;
		}

		if(fwrite(&data, sizeof(Layout), 1, file))
		{
		  fclose(file);
		  return 0;
		}
		else
		  fclose(file);
	      }

	      if(alert("WARNING: Save failed!",
		       NULL,
		       "Do you still wish to exit?",
		       "Yes", "No", 0, 0) == 1)
		return 0;
	    }
	  }
	}
	else if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  newGame();
	else if(click_x > UNDO_BUTTON_X1 && click_x < UNDO_BUTTON_X2)
	  undoMove();
	else if(click_x > HELP_BUTTON_X1 && click_x < HELP_BUTTON_X2)
	  giveHelp(1);
	else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	{
	  if(current_view != left_view)
	    update();

	  if(alert("Are you sure you want to quit?",
	      NULL, NULL, "Yes", "No", 0, 0) == 1)
	    return 0;
	}
      }

event_handled:

      click_ready = 0;
    }
    else
      rest(100);
  }

  return 0;
}
Beispiel #13
0
/* handle the load command */
int loader()
{
   char buf[FILENAME_LENGTH];

   strcpy(buf, config_file);

   if (file_select_ex("Load Keyboard Config", buf, "CFG", sizeof(buf), 0, 0)) {
      strlwr(buf);
      strcpy(config_file, buf);

      memcpy(_key_ascii_table, orig_key_ascii_table, sizeof(orig_key_ascii_table));
      memcpy(_key_capslock_table, orig_key_capslock_table, sizeof(orig_key_capslock_table));
      memcpy(_key_shift_table, orig_key_shift_table, sizeof(orig_key_shift_table));
      memcpy(_key_control_table, orig_key_control_table, sizeof(orig_key_control_table));
      memcpy(_key_altgr_lower_table, orig_key_altgr_lower_table, sizeof(orig_key_altgr_lower_table));
      memcpy(_key_altgr_upper_table, orig_key_altgr_upper_table, sizeof(orig_key_altgr_upper_table));
      memcpy(_key_accent1_lower_table, orig_key_accent1_lower_table, sizeof(orig_key_accent1_lower_table));
      memcpy(_key_accent1_upper_table, orig_key_accent1_upper_table, sizeof(orig_key_accent1_upper_table));
      memcpy(_key_accent2_lower_table, orig_key_accent2_lower_table, sizeof(orig_key_accent2_lower_table));
      memcpy(_key_accent2_upper_table, orig_key_accent2_upper_table, sizeof(orig_key_accent2_upper_table));
      memcpy(_key_accent3_lower_table, orig_key_accent3_lower_table, sizeof(orig_key_accent3_lower_table));
      memcpy(_key_accent3_upper_table, orig_key_accent3_upper_table, sizeof(orig_key_accent3_upper_table));
      memcpy(_key_accent4_lower_table, orig_key_accent4_lower_table, sizeof(orig_key_accent4_lower_table));
      memcpy(_key_accent4_upper_table, orig_key_accent4_upper_table, sizeof(orig_key_accent4_upper_table));

      push_config_state();
      set_config_file(buf);

      load_table(_key_ascii_table,               "key_ascii");
      load_table(_key_capslock_table,            "key_capslock");
      load_table(_key_shift_table,               "key_shift");
      load_table(_key_control_table,             "key_control");

      load_table(_key_altgr_lower_table,         "key_altgr");
      load_table(_key_altgr_upper_table,         "key_altgr");

      load_table(_key_altgr_lower_table,         "key_altgr_lower");
      load_table(_key_altgr_upper_table,         "key_altgr_upper");

      load_table(_key_accent1_lower_table,       "key_accent1_lower");
      load_table(_key_accent1_upper_table,       "key_accent1_upper");
      load_table(_key_accent2_lower_table,       "key_accent2_lower");
      load_table(_key_accent2_upper_table,       "key_accent2_upper");
      load_table(_key_accent3_lower_table,       "key_accent3_lower");
      load_table(_key_accent3_upper_table,       "key_accent3_upper");
      load_table(_key_accent4_lower_table,       "key_accent4_lower");
      load_table(_key_accent4_upper_table,       "key_accent4_upper");

      _key_accent1 = get_config_int("key_escape", "accent1", 0);
      _key_accent2 = get_config_int("key_escape", "accent2", 0);
      _key_accent3 = get_config_int("key_escape", "accent3", 0);
      _key_accent4 = get_config_int("key_escape", "accent4", 0);
      _key_accent1_flag = get_config_int("key_escape", "accent1_flag", 0);
      _key_accent2_flag = get_config_int("key_escape", "accent2_flag", 0);
      _key_accent3_flag = get_config_int("key_escape", "accent3_flag", 0);
      _key_accent4_flag = get_config_int("key_escape", "accent4_flag", 0);

      strcpy(keyboard_name, get_config_string(NULL, "keyboard_name", ""));
      main_dlg[11].d2 = strlen(keyboard_name);

      pop_config_state();
   }

   return D_REDRAW;
}
Beispiel #14
0
int main(void)
{
	allegro_init();
	install_keyboard();
	install_mouse();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	buffer = create_bitmap(640, 480);
	vpic[0] = load_pcx("antivirus.dat#virus_red.pcx", pal);
	vpic[1] = load_pcx("antivirus.dat#virus_yellow.pcx", NULL);
	vpic[2] = load_pcx("antivirus.dat#virus_blue.pcx", NULL);
	map = create_bitmap(8, 16);
	clear_bitmap(map);
	set_palette(pal);
	set_mouse_sprite(NULL);
	while(!done)
	{
		if(key[KEY_ESC])
		{
			done = 1;
		}
		if(key[KEY_1])
		{
			virus = 16;
		}
		else if(key[KEY_2])
		{
			virus = 17;
		}
		else if(key[KEY_3])
		{
			virus = 18;
		}
		if(key[KEY_F2])
		{
			if(file_select_ex("Save:", filename, "pcx", 1024, 320, 240))
			{
				save_pcx(filename, map, pal);
			}
			clear_keybuf();
		}
		if(key[KEY_F3])
		{
			if(file_select_ex("Load:", filename, "pcx", 1024, 320, 240))
			{
				destroy_bitmap(map);
				map = load_pcx(filename, NULL);
			}
			clear_keybuf();
		}
		mx = mouse_x;
		my = mouse_y;
		if(mouse_b & 1 && mx / 16 < 8 && my / 16 < 16)
		{
			map->line[my / 16][mx / 16] = virus;
		}
		else if(mouse_b & 2 && mx / 16 < 8 && my / 16 < 16)
		{
			map->line[my / 16][mx / 16] = 0;
		}
		clear_bitmap(buffer);
		for(int i = 0; i < 16; i++)
		{
			for(int j = 0; j < 8; j++)
			{
				if(map->line[i][j])
				{
					draw_sprite(buffer, vpic[map->line[i][j] - 16], j * 16, i * 16);
				}
			}
		}
		draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y);
		blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
	}
	return 0;
}