示例#1
0
文件: langsel.c 项目: gradha/multitet
static char *_get_lang_name_from_file(const char *file_name, char *lang_code)
{
   char *line;
   char buf1[256], buf2[256];

   ASSERT(file_name);
   ASSERT(*file_name);
   ASSERT(lang_code);

   lang_code[0] = file_name[0];
   lang_code[1] = file_name[1];
   lang_code[2] = 0;

   get_executable_name(buf1, sizeof(buf1));
   replace_filename(buf2, buf1, file_name, sizeof(buf2));

   push_config_state();
   set_config_file(buf2);

   line = m_strdup(get_config_string(0, "language_name", ""));
   
   pop_config_state();

   if (*line)
      return line;

   free(line);
   return 0;
}
示例#2
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;
}
示例#3
0
/* read_keyboard_config:
 *  Reads in the keyboard config tables.
 */
static void read_keyboard_config(void)
{
   char filename[1024], tmp1[128], tmp2[128], *ext, *datafile;
   AL_CONST char* name;

   name = get_config_string(uconvert_ascii("system", tmp1), uconvert_ascii("keyboard", tmp2), _keyboard_layout);

   if ((!name) || (!ugetc(name)))
      return;

   ext = uconvert_ascii(".cfg", tmp1);
   datafile = uconvert_ascii("keyboard.dat", tmp2);

   if (find_allegro_resource(filename, name, ext, datafile, NULL, NULL, NULL, sizeof(filename)) != 0)
      return;

   push_config_state();
   set_config_file(filename);

   read_key_table(custom_key_ascii_table,          standard_key_ascii_table,     "key_ascii");
   read_key_table(custom_key_capslock_table,       standard_key_capslock_table,  "key_capslock");
   read_key_table(custom_key_shift_table,          standard_key_shift_table,     "key_shift");
   read_key_table(custom_key_control_table,        standard_key_control_table,   "key_control");

   /* preserve backward compatibility with former unique key_altgr table */
   read_key_table(custom_key_altgr_lower_table,    standard_key_empty_table,     "key_altgr");
   read_key_table(custom_key_altgr_upper_table,    standard_key_empty_table,     "key_altgr");

   read_key_table(custom_key_altgr_lower_table,    custom_key_altgr_lower_table, "key_altgr_lower");
   read_key_table(custom_key_altgr_upper_table,    custom_key_altgr_upper_table, "key_altgr_upper");

   read_key_table(custom_key_accent1_lower_table,  standard_key_empty_table,     "key_accent1_lower");
   read_key_table(custom_key_accent1_upper_table,  standard_key_empty_table,     "key_accent1_upper");
   read_key_table(custom_key_accent2_lower_table,  standard_key_empty_table,     "key_accent2_lower");
   read_key_table(custom_key_accent2_upper_table,  standard_key_empty_table,     "key_accent2_upper");
   read_key_table(custom_key_accent3_lower_table,  standard_key_empty_table,     "key_accent3_lower");
   read_key_table(custom_key_accent3_upper_table,  standard_key_empty_table,     "key_accent3_upper");
   read_key_table(custom_key_accent4_lower_table,  standard_key_empty_table,     "key_accent4_lower");
   read_key_table(custom_key_accent4_upper_table,  standard_key_empty_table,     "key_accent4_upper");

   _key_accent1 = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent1", tmp2), 0);
   _key_accent2 = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent2", tmp2), 0);
   _key_accent3 = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent3", tmp2), 0);
   _key_accent4 = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent4", tmp2), 0);

   _key_accent1_flag = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent1_flag", tmp2), 0);
   _key_accent2_flag = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent2_flag", tmp2), 0);
   _key_accent3_flag = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent3_flag", tmp2), 0);
   _key_accent4_flag = get_config_int(uconvert_ascii("key_escape", tmp1), uconvert_ascii("accent4_flag", tmp2), 0);

   pop_config_state();

   set_custom_keyboard();

   update_key_descriptions();
}
示例#4
0
void ShipData::lock()
{
	STACKTRACE;
	if (references == 0) {
		push_config_state();	 //can screw up badly if an error occurs while loading...
		load();
		pop_config_state();
	}
	references += 1;
}
示例#5
0
文件: joystick.c 项目: ifilex/SRC
/* save_joystick_data:
 *  After calibrating a joystick, this function can be used to save the
 *  information into the specified file, from where it can later be 
 *  restored by calling load_joystick_data().
 */
int save_joystick_data(char *filename)
{
   if (filename) {
      push_config_state();
      set_config_file(filename);
   }

   set_config_id("joystick", "joytype", joy_type);

   if ((joystick_driver) && (joystick_driver->save_data))
      joystick_driver->save_data();

   if (filename)
      pop_config_state();

   return 0;
}
示例#6
0
文件: joystick.c 项目: ifilex/SRC
/* load_joystick_data:
 *  Restores a set of joystick calibration data previously saved by
 *  save_joystick_data().
 */
int load_joystick_data(char *filename)
{
   int ret, c;

   joy_loading = TRUE;

   if (_joystick_installed)
      remove_joystick();

   if (filename) {
      push_config_state();
      set_config_file(filename);
   }

   joy_type = get_config_id("joystick", "joytype", -1);

   if (joy_type < 0) {
      joy_type = JOY_TYPE_NONE;
      ret = -1;
   }
   else {
      ret = install_joystick(joy_type);

      if (ret == 0) {
	 if (joystick_driver->load_data)
	    ret = joystick_driver->load_data();
      }
   }

   if (filename)
      pop_config_state();

   if (ret == 0) {
      for (c=0; c<num_joysticks; c++)
	 update_calib(c);

      poll_joystick();
   }

   joy_loading = FALSE;

   return ret;
}
示例#7
0
文件: inidriv.c 项目: neiderm/turaco
// saves the current palette
void SavePalette(int NumCols, int PalIndex, int CurrentPal, int IniFilePalNum)
{
   char * Buffer;
   char NumBuf[10];
   int j;

   // This buffer will hold number like the following:
   // 4 255 255 255  255 255 255
   // Note the 10 allows for the first number, space and a bit of overhead
   // the 13 allows for "255 255 255  ".
   // This is dynamically allocated as we don't know how much space is required
   // until we know the number of colours
   Buffer = malloc(10 + (NumCols * 13));
   if (Buffer == NULL)
   {
      alert("Error", "Failed to save palette!", NULL,  "&Okay", NULL, 'O', 0);
      return;
   }
   sprintf(Buffer, "%d ", NumCols);

   for (j = 0; j < NumCols; j ++)
   {
      int Offset = NumCols * CurrentPal;

      sprintf(NumBuf, "%d ", ColPalettes[PalIndex][j + Offset].r);
      strcat(Buffer, NumBuf);
      sprintf(NumBuf, "%d ", ColPalettes[PalIndex][j + Offset].g);
      strcat(Buffer, NumBuf);
      sprintf(NumBuf, "%d  ", ColPalettes[PalIndex][j + Offset].b);
      strcat(Buffer, NumBuf);
   }

   // now write out the buffer
   sprintf(NumBuf, "Palette%d", IniFilePalNum);

   push_config_state();
   set_config_file(INI_Driver_Path);
   set_config_string("Palette", NumBuf, Buffer);
   pop_config_state();

   free (Buffer);
}
示例#8
0
文件: keys.cpp 项目: Fomka/ufo2000
void keyswitch(int keyswitch_lang)
{
	push_config_state();
	set_config_file(F("$(home)/ufo2000.ini"));

	switch (keyswitch_lang) {
		case 0: {
			const char *current_keyboard = get_config_string("system", "keyboard", "us");
			const char *primary_keyboard = get_config_string("system", "primary_keyboard", "us");
			const char *secondary_keyboard = get_config_string("system", "secondary_keyboard", "ru");
			if (strcmp(current_keyboard, primary_keyboard) == 0)
				set_config_string("system", "keyboard", secondary_keyboard);
			else
				set_config_string("system", "keyboard", primary_keyboard);
			break;
		}
		case KEY_E: 
			set_config_string("system", "keyboard", "us"); 
			break;
		case KEY_R: 
			set_config_string("system", "keyboard", "ru"); 
			break;
		case KEY_B: 
			set_config_string("system", "keyboard", "by"); 
			break;
		case KEY_P: 
			set_config_string("system", "keyboard", "pl"); 
			break;
		case KEY_D: 
			set_config_string("system", "keyboard", "de"); 
			break;
		default: 
			pop_config_state(); 
			return;
	}
	
	clear_keybuf();
	remove_keyboard();
	install_keyboard();
	pop_config_state();
}
示例#9
0
void Preferences::serializeDocPref(const app::Document* doc, app::DocumentPreferences* docPref, bool save)
{
  bool specific_file = false;

  if (doc) {
    if (!doc->isAssociatedToFile())
      return;

    push_config_state();
    set_config_file(docConfigFileName(doc).c_str());
    specific_file = true;
  }

  if (save)
    docPref->save();
  else
    docPref->load();

  if (specific_file) {
    flush_config_file();
    pop_config_state();
  }
}
示例#10
0
文件: inidriv.c 项目: neiderm/turaco
// assumes inifilename includes fully qualified path
BOOL LoadDriver(char * INIFileName)
{
   BOOL retval;
   char INIDriverName[128];
   char * fname = get_filename(INIFileName);
   int i = 0;

   // free any currently loaded driver
   FreeDriver();
   
   /* setup INI Driver name */
   // JERR -- since the file selector uses a full path, we lose this next line.
   // when i write a new file loader dialog, this will change back...
   //sprintf(INIDriverName, "drivers/%s", fname);

   sprintf(INIDriverName, "%s", fname);
   
   /* set up ROMDirName - ini filename without extension */
   while ((fname[i] != '\0') && (fname[i] != '.'))
   {
      ROMDirName[i] = fname[i];
      i ++;
   }
   ROMDirName[i] = 0;

   // load the data from the INI file
   push_config_state();

   //set_config_file(INIDriverName);
   set_config_file(INIFileName);

   sprintf(INI_Driver_Path, "%s", INIFileName);

   retval = ReadFromDriverIniFile();
   
   pop_config_state();

   // did the INI read fail?
   if (retval == FALSE)
      return retval;

   // load graphics roms into memory
   retval = LoadGfxRomData();

   // if load failed then free all INI Driver memory and fail
   if (retval == FALSE)
   {

      if(GfxBanks)         free(GfxBanks);
      if(GfxBankExtraInfo) free(GfxBankExtraInfo);
      if(GfxRoms)          free(GfxRoms);
      GfxBanks = NULL; GfxBankExtraInfo = NULL; GfxRoms = NULL; // GN:
      return retval;
   }

   // create bitmaps for graphics banks
   retval = AllocateGfxBanks();

   // if load failed then free all INI Driver memory and loaded roms and fail
   if (retval == FALSE)
   {
      if(GfxBanks)         free(GfxBanks);
      if(GfxBankExtraInfo) free(GfxBankExtraInfo);
      if(GfxRoms)          free(GfxRoms);
      if(GfxRomData)       free(GfxRomData);
      return retval;
   }

   // now decode the graphics banks
   SwitchGraphicsBank(-1, 0);
   
   // success
   GameDriverLoaded = TRUE;
   
   return retval;
}
示例#11
0
文件: setup.c 项目: rj76/kq
/*! \brief Display configuration menu
 *
 * This is the config menu that is called from the system
 * menu.  Here you can adjust the music or sound volume, or
 * the speed that the battle gauge moves at.
 */
void config_menu (void)
{
   int stop = 0, ptr = 0, p;
   int temp_key = 0;

#ifdef DEBUGMODE
   #define MENU_SIZE 18
#else
   #define MENU_SIZE 17
#endif
   static const char *dc[MENU_SIZE];

   /* Define rows with appropriate spacings for breaks between groups */
   int row[MENU_SIZE];
   for (p = 0; p < 4; p++)
      row[p] = (p + 4) * 8;     // (p * 8) + 32
   for (p = 4; p < 12; p++)
      row[p] = (p + 5) * 8;     // (p * 8) + 40
   for (p = 12; p < 15; p++)
      row[p] = (p + 6) * 8;     // (p * 8) + 48
   for (p = 15; p < MENU_SIZE; p++)
      row[p] = (p + 7) * 8;     // (p * 8) + 56

   /* Helper strings */
   dc[0]=_("Display KQ in a window.");
   dc[1]=_("Stretch to fit 640x480 resolution.");
   dc[2]=_("Display the frame rate during play.");
   dc[3]=_("Wait for vertical retrace.");
   dc[4]=_("Key used to move up.");
   dc[5]=_("Key used to move down.");
   dc[6]=_("Key used to move left.");
   dc[7]=_("Key used to move right.");
   dc[8]=_("Key used to confirm action.");
   dc[9]=_("Key used to cancel action.");
   dc[10]=_("Key used to call character menu.");
   dc[11]=_("Key used to call system menu.");
   dc[12]=_("Toggle sound and music on/off.");
   dc[13]=_("Overall sound volume (affects music).");
   dc[14]=_("Music volume.");
   dc[15]=_("Animation speed-ups for slow machines.");
   dc[16]=_("Toggle how to allocate CPU usage.");
#ifdef DEBUGMODE
      dc[17]=_("Things you can do only in DebugMode.");
#endif

   unpress ();
   push_config_state ();
   set_config_file (kqres (SETTINGS_DIR, "kq.cfg"));
   while (!stop) {
      check_animation ();
      drawmap ();
      menubox (double_buffer, 88 + xofs, yofs, 16, 1, BLUE);
      print_font (double_buffer, 96 + xofs, 8 + yofs, _("KQ Configuration"),
                  FGOLD);
      menubox (double_buffer, 32 + xofs, 24 + yofs, 30, MENU_SIZE + 3, BLUE);

      citem (row[0], _("Windowed mode:"), windowed == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[1], _("Stretch Display:"), stretch_view == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[2], _("Show Frame Rate:"), show_frate == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[3], _("Wait for Retrace:"), wait_retrace == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[4], _("Up Key:"), kq_keyname (kup), FNORMAL);
      citem (row[5], _("Down Key:"), kq_keyname (kdown), FNORMAL);
      citem (row[6], _("Left Key:"), kq_keyname (kleft), FNORMAL);
      citem (row[7], _("Right Key:"), kq_keyname (kright), FNORMAL);
      citem (row[8], _("Confirm Key:"), kq_keyname (kalt), FNORMAL);
      citem (row[9], _("Cancel Key:"), kq_keyname (kctrl), FNORMAL);
      citem (row[10], _("Menu Key:"), kq_keyname (kenter), FNORMAL);
      citem (row[11], _("System Menu Key:"), kq_keyname (kesc), FNORMAL);
      citem (row[12], _("Sound System:"), is_sound ? _("ON") : _("OFF"), FNORMAL);

      p = FNORMAL;
      /* TT: This needs to check for ==0 because 1 means sound init */
      if (is_sound == 0)
         p = FDARK;

      sprintf (strbuf, "%3d%%", gsvol * 100 / 250);
      citem (row[13], _("Sound Volume:"), strbuf, p);

      sprintf (strbuf, "%3d%%", gmvol * 100 / 250);
      citem (row[14], _("Music Volume:"), strbuf, p);

      citem (row[15], _("Slow Computer:"), slow_computer ? _("YES") : _("NO"), FNORMAL);

      if (cpu_usage)
         sprintf (strbuf, _("rest(%d)"), cpu_usage - 1);
      else
         sprintf (strbuf, "yield_timeslice()");
      citem (row[16], _("CPU Usage:"), strbuf, FNORMAL);

#ifdef DEBUGMODE
      if (debugging)
         sprintf (strbuf, "%d", debugging);
      citem (row[17], _("DebugMode Stuff:"), debugging ? strbuf : _("OFF"), FNORMAL);
#endif

      /* This affects the VISUAL placement of the arrow */
      p = ptr;
      if (ptr > 3)
         p++;
      if (ptr > 11)
         p++;
      if (ptr > 14)
         p++;
      draw_sprite (double_buffer, menuptr, 32 + xofs, p * 8 + 32 + yofs);

      /* This is the bottom window, where the description goes */
      menubox (double_buffer, xofs, 216 + yofs, 38, 1, BLUE);
      print_font (double_buffer, 8 + xofs, 224 + yofs, dc[ptr], FNORMAL);
      blit2screen (xofs, yofs);

      readcontrols ();
      if (up) {
         unpress ();
         // "jump" over unusable options
         if (ptr == 15 && is_sound == 0)
            ptr -= 2;
         ptr--;
         if (ptr < 0)
            ptr = MENU_SIZE - 1;
         play_effect (SND_CLICK, 128);
      }
      if (down) {
         unpress ();
         // "jump" over unusable options
         if (ptr == 12 && is_sound == 0)
            ptr += 2;
         ptr++;
         if (ptr > MENU_SIZE - 1)
            ptr = 0;
         play_effect (SND_CLICK, 128);
      }
      if (balt) {
         unpress ();
         switch (ptr) {
         case 0:
#ifdef __DJGPP__
            text_ex (B_TEXT, 255,
                     _("This version of KQ was compiled for DOS and does not support windowed mode"));
#else
            text_ex (B_TEXT, 255,
                     _("Changing the display mode to or from windowed view could have serious ramifications. It is advised that you save first."));
            if (windowed == 0)
               sprintf (strbuf, _("Switch to windowed mode?"));
            else
               sprintf (strbuf, _("Switch to full screen?"));
            p = prompt (255, 2, B_TEXT, strbuf, _("  no"), _("  yes"), "");
            if (p == 1) {
               if (windowed == 0)
                  windowed = 1;
               else
                  windowed = 0;
               set_config_int (NULL, "windowed", windowed);
               set_graphics_mode ();
            }
#endif
            break;
         case 1:
#ifdef __DJGPP__
            text_ex (B_TEXT, 255,
                     _("This version of KQ was compiled for DOS and does not support stretching"));
#else
            text_ex (B_TEXT, 255,
                     _("Changing the stretched view option could have serious ramifications. It is advised that you save your game before trying this."));
            if (stretch_view == 0)
               sprintf (strbuf, _("Try to stretch the display?"));
            else
               sprintf (strbuf, _("Switch to unstretched display?"));
            p = prompt (255, 2, B_TEXT, strbuf, _("  no"), _("  yes"), "");
            if (p == 1) {
               if (stretch_view == 0)
                  stretch_view = 1;
               else
                  stretch_view = 0;
               set_config_int (NULL, "stretch_view", stretch_view);
               set_graphics_mode ();
            }
#endif
            break;
         case 2:
            if (show_frate == 0)
               show_frate = 1;
            else
               show_frate = 0;
            set_config_int (NULL, "show_frate", show_frate);
            break;
         case 3:
            if (wait_retrace == 0)
               wait_retrace = 1;
            else
               wait_retrace = 0;
            set_config_int (NULL, "wait_retrace", wait_retrace);
            break;
         case 4:
            while ((temp_key = getakey ()) == 0);
            kup = temp_key;
            unpress ();
            set_config_int (NULL, "kup", kup);
            break;
         case 5:
            while ((temp_key = getakey ()) == 0);
            kdown = temp_key;
            unpress ();
            set_config_int (NULL, "kdown", kdown);
            break;
         case 6:
            while ((temp_key = getakey ()) == 0);
            kleft = temp_key;
            unpress ();
            set_config_int (NULL, "kleft", kleft);
            break;
         case 7:
            while ((temp_key = getakey ()) == 0);
            kright = temp_key;
            unpress ();
            set_config_int (NULL, "kright", kright);
            break;
         case 8:
            while ((temp_key = getakey ()) == 0);
            kalt = temp_key;
            unpress ();
            set_config_int (NULL, "kalt", kalt);
            break;
         case 9:
            while ((temp_key = getakey ()) == 0);
            kctrl = temp_key;
            unpress ();
            set_config_int (NULL, "kctrl", kctrl);
            break;
         case 10:
            while ((temp_key = getakey ()) == 0);
            kenter = temp_key;
            unpress ();
            set_config_int (NULL, "kenter", kenter);
            break;
         case 11:
            while ((temp_key = getakey ()) == 0);
            kesc = temp_key;
            unpress ();
            set_config_int (NULL, "kesc", kesc);
            break;
         case 12:
            if (is_sound == 2)
               sound_init ();
            else {
               if (is_sound == 0) {
                  is_sound = 1;
                  print_font (double_buffer, 92 + 2 + xofs, 204 + yofs,
                              _("...please wait..."), FNORMAL);
                  blit2screen (xofs, yofs);
                  sound_init ();
                  play_music (g_map.song_file, 0);
               }
            }
            set_config_int (NULL, "is_sound", is_sound != 0);
            break;
         case 13:
            if (is_sound == 2) {
               p = getavalue (_("Sound Volume"), 0, 25, gsvol / 10, 1);
               if (p != -1)
                  gsvol = p * 10;

               /* make sure to set it no matter what */
               set_volume (gsvol, 0);
               set_config_int (NULL, "gsvol", gsvol);
            } else
               /* Not as daft as it seems, SND_BAD also wobbles the screen */
               play_effect (SND_BAD, 128);
            break;
         case 14:
            if (is_sound == 2) {
               p = getavalue (_("Music Volume"), 0, 25, gmvol / 10, 1);
               if (p != -1)
                  gmvol = p * 10;

               /* make sure to set it no matter what */
               set_music_volume (gmvol / 250.0);
               set_config_int (NULL, "gmvol", gmvol);
            } else
               play_effect (SND_BAD, 128);
            break;
         case 15:
            /* TT: toggle slow_computer */
            slow_computer = !slow_computer;
            set_config_int (NULL, "slow_computer", slow_computer);
            break;
         case 16:
            /* TT: Adjust the CPU usage:yield_timeslice() or rest() */
            cpu_usage++;
            if (cpu_usage > 2)
               cpu_usage = 0;
            break;
#ifdef DEBUGMODE
         case 17:
            /* TT: Things we only have access to when we're in debug mode */
            if (debugging < 4)
               debugging++;
            else
               debugging = 0;
            break;
#endif
         }
      }
      if (bctrl) {
         unpress ();
         stop = 1;
      }
   }
   pop_config_state ();
}
示例#12
0
文件: setup.c 项目: rj76/kq
/*! \brief Parse allegro file kq.cfg
 *
 * This is like parse_setup(), but using Allegro format files
 *
 * \author PH
 * \date 20030831
 */
static void parse_allegro_setup (void)
{
   const char *cfg = kqres (SETTINGS_DIR, "kq.cfg");
   if (!exists (cfg)) {
      /* config file does not exist. Fall back to setup.cfg */
      /* Transitional code */
      parse_jb_setup ();
      push_config_state ();
      set_config_file (cfg);

      set_config_int (NULL, "skip_intro", skip_intro);
      set_config_int (NULL, "windowed", windowed);

      set_config_int (NULL, "stretch_view", stretch_view);
      set_config_int (NULL, "show_frate", show_frate);
      set_config_int (NULL, "is_sound", is_sound);
      set_config_int (NULL, "use_joy", use_joy);
      set_config_int (NULL, "slow_computer", slow_computer);

      set_config_int (NULL, "kup", kup);
      set_config_int (NULL, "kdown", kdown);
      set_config_int (NULL, "kleft", kleft);
      set_config_int (NULL, "kright", kright);
      set_config_int (NULL, "kesc", kesc);
      set_config_int (NULL, "kalt", kalt);
      set_config_int (NULL, "kctrl", kctrl);
      set_config_int (NULL, "kenter", kenter);

#ifdef DEBUGMODE
      set_config_int (NULL, "debugging", debugging);
#endif

      pop_config_state ();
      return;
   }
   push_config_state ();
   set_config_file (cfg);

   /* NB. JB's config file uses intro=yes --> skip_intro=0 */
   skip_intro = get_config_int (NULL, "skip_intro", 0);
#ifdef __DJGPP__
   /* In DJGPP, it's always non-windowed non-stretched (DOS-era stuff!) */
   windowed = 0;
   stretch_view = 0;
#else
   windowed = get_config_int (NULL, "windowed", 1);
   stretch_view = get_config_int (NULL, "stretch_view", 1);
#endif
   wait_retrace = get_config_int (NULL, "wait_retrace", 1);
   show_frate = get_config_int (NULL, "show_frate", 0);
   is_sound = get_config_int (NULL, "is_sound", 1);
   use_joy = get_config_int (NULL, "use_joy", 0);
   slow_computer = get_config_int (NULL, "slow_computer", 0);
   cpu_usage = get_config_int (NULL, "cpu_usage", 2);
#ifdef KQ_CHEATS
   cheat = get_config_int (NULL, "cheat", 0);
   no_random_encounters = get_config_int (NULL, "no_random_encounters", 0);
   no_monsters = get_config_int (NULL, "no_monsters", 0);
   every_hit_999 = get_config_int (NULL, "every_hit_999", 0);
#endif
#ifdef DEBUGMODE
   debugging = get_config_int (NULL, "debugging", 0);
#endif

   kup = get_config_int (NULL, "kup", KEY_UP);
   kdown = get_config_int (NULL, "kdown", KEY_DOWN);
   kleft = get_config_int (NULL, "kleft", KEY_LEFT);
   kright = get_config_int (NULL, "kright", KEY_RIGHT);
   kesc = get_config_int (NULL, "kesc", KEY_ESC);
   kalt = get_config_int (NULL, "kalt", KEY_ALT);
   kctrl = get_config_int (NULL, "kctrl", KEY_LCONTROL);
   kenter = get_config_int (NULL, "kenter", KEY_ENTER);
   pop_config_state ();
}
示例#13
0
/* See README for details.
 */
void
abitmap_init (char const *path, DATAFILE *datafile)
{
	int i;
	int prev[10];
	int cv;
	char str[1024];
	DATAFILE *dat;

	cv = get_color_conversion ();
	set_color_conversion (COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);

	used_bitmaps_cleanup ();

	push_config_state ();
	dat = set_theme_config (path, datafile);
	if (dat != datafile)
		used_dat = dat;

	theme->fg_color = get_color_string ("fg", "0x000000");
	theme->bg_color = get_color_string ("bg", "0xffffff");
	theme->mg_color = get_color_string ("mg", "0x808080");

	theme->textpushx = get_config_int ("agup.cfg", "px", 0);
	theme->textpushy = get_config_int ("agup.cfg", "py", 0);

	for (i = 0; bload[i].name; i++) {
		int j;
		int s;

		char const *suffix[] = { "", "_hl", "_dis" };

		for (s = 0; bload[i].name[s] == ' '; s++);

		for (j = 0; j < 3; j++) {
			char **argv = NULL;
			int argc = 0;
			BITMAP *bmp = NULL;
			int got_color = 0;

			theme->bitmaps[bload[i].elem][j].bmp = NULL;
			theme->bitmaps[bload[i].elem][j].flags = 0;
			theme->bitmaps[bload[i].elem][j].bl = 0;
			theme->bitmaps[bload[i].elem][j].br = 0;
			theme->bitmaps[bload[i].elem][j].bt = 0;
			theme->bitmaps[bload[i].elem][j].bb = 0;

			sprintf (str, "%s%s", bload[i].name + s, suffix[j]);
			argv = get_config_argv ("agup.cfg", str, &argc);

			TRACE ("%s: ", str);

			if (argc) {
				bmp = find_theme_bitmap (dat, argv[0]);
			}

			if (bmp) {
				int a;

				theme->bitmaps[bload[i].elem][j].bmp = bmp;

				for (a = 1; a < argc; a++) {
					if (!strcmp (argv[a], "stretch"))
						theme->bitmaps[bload[i].elem][j].flags |=
							ABMAP_STRETCH_H | ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "center"))
						theme->bitmaps[bload[i].elem][j].flags |=
								ABMAP_CENTER_H | ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "stretchh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_H;
					else if (!strcmp (argv[a], "centerh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_H;
					else if (!strcmp (argv[a], "alignh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_H;
					else if (!strcmp (argv[a], "stretchv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "centerv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "alignv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_V;
					else if (!strcmp (argv[a], "cut")) {
						int cx, cy, cw, ch;
						a++;
						if (a < argc) {
							cx = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								cy = strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									cw = strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										BITMAP *sub;
										ch = strtol (argv[a], NULL, 10);
										if (cw <= 0)
											cw += bmp->w;
										if (ch <= 0)
											ch += bmp->h;
										sub = create_sub_bitmap (bmp, cx, cy, cw, ch);
										used_bitmap (sub, NULL);
										theme->bitmaps[bload[i].elem][j].bmp = sub;
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "border")) {
						a++;
						if (a < argc) {
							theme->bitmaps[bload[i].elem][j].bl = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								theme->bitmaps[bload[i].elem][j].br =
									strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									theme->bitmaps[bload[i].elem][j].bt =
										strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										theme->bitmaps[bload[i].elem][j].bb =
											strtol (argv[a], NULL, 10);
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "color")) {
						a++;
						if (a < argc) {
							int rgb32 = strtol (argv[a], NULL, 0);

							theme->bitmaps[bload[i].elem][j].color =
								makecol (rgb32 >> 16, (rgb32 >> 8) & 255,
								rgb32 & 255);
							got_color = 1;
							TRACE ("color %06x ", rgb32);
						}
					}
				}
				TRACE ("loaded successfully.\n");
			} else {
				/* If everything fails, try to inherit from another bitmap. */
				if (j) {
示例#14
0
int main(int argc, char *argv[])
{
   static char config_override[] = "[system]\nkeyboard = \n";
   RGB black_rgb = {0, 0, 0, 0};
   DATAFILE *font_data;
   int c;

   if (allegro_init() != 0)
      exit(EXIT_FAILURE);

   if (argc > 1) {
      if (strcmp(argv[1], "--split-altgr") == 0) {
         split_altgr = TRUE;
      }
      else {
         allegro_message("Error: unrecognized option\n");
         exit(EXIT_FAILURE);
      }
   }

   install_mouse();
   install_timer();

   push_config_state();
   override_config_data(config_override, sizeof(config_override));
   install_keyboard();
   pop_config_state();

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

   memcpy(my_key_ascii_table, _key_ascii_table, sizeof(my_key_ascii_table));
   memcpy(my_key_capslock_table, _key_capslock_table, sizeof(my_key_capslock_table));
   memcpy(my_key_shift_table, _key_shift_table, sizeof(my_key_shift_table));
   memcpy(my_key_control_table, _key_control_table, sizeof(my_key_control_table));
   memcpy(my_key_altgr_lower_table, _key_altgr_lower_table, sizeof(my_key_altgr_lower_table));
   memcpy(my_key_altgr_upper_table, _key_altgr_upper_table, sizeof(my_key_altgr_upper_table));
   memcpy(my_key_accent1_lower_table, _key_accent1_lower_table, sizeof(my_key_accent1_lower_table));
   memcpy(my_key_accent1_upper_table, _key_accent1_upper_table, sizeof(my_key_accent1_upper_table));
   memcpy(my_key_accent2_lower_table, _key_accent2_lower_table, sizeof(my_key_accent2_lower_table));
   memcpy(my_key_accent2_upper_table, _key_accent2_upper_table, sizeof(my_key_accent2_upper_table));
   memcpy(my_key_accent3_lower_table, _key_accent3_lower_table, sizeof(my_key_accent3_lower_table));
   memcpy(my_key_accent3_upper_table, _key_accent3_upper_table, sizeof(my_key_accent3_upper_table));
   memcpy(my_key_accent4_lower_table, _key_accent4_lower_table, sizeof(my_key_accent4_lower_table));
   memcpy(my_key_accent4_upper_table, _key_accent4_upper_table, sizeof(my_key_accent4_upper_table));

   _key_ascii_table = my_key_ascii_table;
   _key_capslock_table = my_key_capslock_table;
   _key_shift_table = my_key_shift_table;
   _key_control_table = my_key_control_table;
   _key_altgr_lower_table = my_key_altgr_lower_table;
   _key_altgr_upper_table = my_key_altgr_upper_table;
   _key_accent1_lower_table = my_key_accent1_lower_table;
   _key_accent1_upper_table = my_key_accent1_upper_table;
   _key_accent2_lower_table = my_key_accent2_lower_table;
   _key_accent2_upper_table = my_key_accent2_upper_table;
   _key_accent3_lower_table = my_key_accent3_lower_table;
   _key_accent3_upper_table = my_key_accent3_upper_table;
   _key_accent4_lower_table = my_key_accent4_lower_table;
   _key_accent4_upper_table = my_key_accent4_upper_table;

   edit_menu[0].dp = _key_ascii_table;
   edit_menu[1].dp = _key_capslock_table;
   edit_menu[2].dp = _key_shift_table;
   edit_menu[3].dp = _key_control_table;
   edit_menu[4].dp = _key_altgr_lower_table;
   edit_menu[5].dp = _key_altgr_upper_table;
   edit_menu[6].dp = _key_accent1_lower_table;
   edit_menu[7].dp = _key_accent1_upper_table;
   edit_menu[8].dp = _key_accent2_lower_table;
   edit_menu[9].dp = _key_accent2_upper_table;
   edit_menu[10].dp = _key_accent3_lower_table;
   edit_menu[11].dp = _key_accent3_upper_table;
   edit_menu[12].dp = _key_accent4_lower_table;
   edit_menu[13].dp = _key_accent4_upper_table;

   if (!split_altgr)
      edit_menu[5].flags = D_DISABLED;

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   set_palette(desktop_palette);
   set_color(0, &black_rgb);
   gui_fg_color = palette_color[255];
   gui_bg_color = palette_color[16];

   /* We set up colors to match screen color depth (in case it changed) */
   for (c = 0; main_dlg[c].proc; c++) {
      main_dlg[c].fg = palette_color[main_dlg[c].fg];
      main_dlg[c].bg = palette_color[main_dlg[c].bg];
   }
   for (c = 0; ascii_dlg[c].proc; c++) {
      ascii_dlg[c].fg = palette_color[ascii_dlg[c].fg];
      ascii_dlg[c].bg = palette_color[ascii_dlg[c].bg];
   }
   for (c = 0; editor_dlg[c].proc; c++) {
      editor_dlg[c].fg = palette_color[editor_dlg[c].fg];
      editor_dlg[c].bg = palette_color[editor_dlg[c].bg];
   }
   for (c = 0; accent_dlg[c].proc; c++) {
      accent_dlg[c].fg = palette_color[accent_dlg[c].fg];
      accent_dlg[c].bg = palette_color[accent_dlg[c].bg];
   }

   _key_standard_kb = FALSE;

   font_data = load_datafile_object ("keyconf.dat", "BASE_FONT");

   if (font_data)
      font = font_data->dat;

   do_dialog(main_dlg, -1);

   if (font_data)
      unload_datafile_object(font_data);

   return 0;
}
示例#15
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;
}
示例#16
0
int main(void)
{
   int w,h,bpp;
   int windowed;
   int count;
   char **data;

   char *title;
   char *filename;
   int  r,g,b;

   BITMAP *background;
   int     display;
   RGB     pal[256];

   int    x, y;

   /* you should always do this at the start of Allegro programs */
   if (allegro_init() != 0)
      return 1;
   /* set up the keyboard handler */
   install_keyboard(); 

   /* save the current ini file, then set the program specific one */
   push_config_state();
   set_config_file("exconfig.ini");

   /* the gfx mode is stored like this:
    *    640  480 16
    * the get_config_argv() function returns a pointer to a char
    * array, and stores the size of the char array in an int
    */
   data = get_config_argv("graphics", "mode", &count);
   if (count != 3) {
      /* We expect only 3 parameters */
      allegro_message("Found %i parameters in graphics.mode instead of "
		      "the 3 expected.\n", count);
      w = 320;
      h = 200;
      bpp = 8;
   }
   else {
      w = atoi(data[0]);
      h = atoi(data[1]);
      bpp = atoi(data[2]);       
   }

   /* Should we use a windowed mode? 
    * In the config file this is stored as either FALSE or TRUE.
    * So we need to read a string and see what it contains.
    * If the entry is not found, we use "FALSE" by default
    */
   if (ustricmp(get_config_string("graphics", "windowed", "FALSE"), "FALSE") == 0)
      windowed = GFX_AUTODETECT_FULLSCREEN;
   else
      windowed = GFX_AUTODETECT_WINDOWED;

   /* the title string 
    * The string returned is stored inside of the config system
    * and would be lost if we call pop_config_state(), so we create
    * a copy of it.
    */
   title = ustrdup(get_config_string("content", "headline", "<no headline>"));

   /* the title color 
    * once again this is stored as three ints in one line
    */
   data = get_config_argv("content", "headercolor", &count);
   if (count != 3) {
      /* We expect only 3 parameters */
      allegro_message("Found %i parameters in content.headercolor "
		      "instead of the 3 expected.\n", count);
      r = g = b = 255;
   }
   else {
      r = atoi(data[0]);
      g = atoi(data[1]);
      b = atoi(data[2]);       
   }

   /* The image file to read 
    * The string returned is stored inside of the config system
    * and would be lost if we call pop_config_state(), so we create
    * a copy of it.
    */   
   filename = ustrdup(get_config_string("content", "image", "mysha.pcx"));

   /* and it's tiling mode */
   display = get_config_int("content", "display", 0);
   if (display <0 || display > 2) {
      allegro_message("content.display must be within 0..2\n");
      display = 0; 
   } 

   /* restore the old config file */
   pop_config_state();


   /* set the graphics mode */
   set_color_depth(bpp);
   if (set_gfx_mode(windowed, w, h, 0, 0) != 0) {
      allegro_message("Unable to set mode %ix%i with %ibpp\n", w, h, bpp);
      free(filename);
      free(title);
      exit(-1);           
   }         

   /* Clear the screen */
   clear_bitmap(screen);   

   /* load the image */
   background = load_bitmap(filename, pal);
   if (background != NULL) {
      set_palette(pal);

      switch (display) {

	 case 0: /* stretch */
	    stretch_blit(background, screen, 0, 0, background->w,
			 background->h, 0, 0, SCREEN_W, SCREEN_H);
	 break;

	 case 1: /* center */
	    blit(background, screen, 0, 0, (SCREEN_W - background->w)/2,
		 (SCREEN_H - background->h)/2, background->w, background->h);
	 break;

	 case 2: /* tile */
	    for (y = 0; y < SCREEN_H; y += background->h)
	       for (x = 0; x < SCREEN_W; x += background->w)
		  blit(background, screen, 0, 0, x, y,
		       background->w, background->h);
         break; 
      }
   }
   else {
      textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H/2,
			   makecol(r,g,b), -1, "%s not found", filename);
   }

   textout_centre_ex(screen, font, title, SCREEN_W/2, 20, makecol(r,g,b), -1);

   readkey();

   free(filename);
   free(title);

   return 0;
}