Example #1
0
void InitMenu()
{
  /* Reset variables */
  TabIndex = TAB_ABOUT;
  Background = NULL;

  /* Initialize paths */
  sprintf(SaveStatePath, "%ssavedata/", pl_psp_get_app_directory());
  sprintf(ScreenshotPath, "%sscreenshot/",  pl_psp_get_app_directory());
  sprintf(GamePath, "%s", pl_psp_get_app_directory());

  if (!pl_file_exists(SaveStatePath))
    pl_file_mkdir_recursive(SaveStatePath);

  /* Initialize options */
  LoadOptions();

  InitEmulator();

  /* Load the background image */
  pl_file_path background;
  snprintf(background, sizeof(background) - 1, "%sbackground.png",
           pl_psp_get_app_directory());
  Background = pspImageLoadPng(background);
  //Background = pspImageLoadPng("background.png");

  /* Init NoSaveState icon image */
  NoSaveIcon = pspImageCreate(136, 114, PSP_IMAGE_16BPP);
  pspImageClear(NoSaveIcon, RGB(0x0c,0,0x3f));

  /* Initialize state menu */
  int i;
  pl_menu_item *item;
  for (i = 0; i < 10; i++)
  {
    item = pl_menu_append_item(&SaveStateGallery.Menu, i, NULL);
    pl_menu_set_item_help_text(item, EmptySlotText);
  }

  /* Initialize menus */
  pl_menu_create(&SystemUiMenu.Menu, SystemMenuDef);
  pl_menu_create(&OptionUiMenu.Menu, OptionMenuDef);
  pl_menu_create(&ControlUiMenu.Menu, ControlMenuDef);

  /* Load default configuration */
  LoadButtonConfig();

  /* Initialize UI components */
  UiMetric.Background = Background;
  UiMetric.Font = &PspStockFont;
  UiMetric.Left = 16;
  UiMetric.Top = 48;
  UiMetric.Right = 944;
  UiMetric.Bottom = 500;
  UiMetric.OkButton = (!Options.ControlMode) ? PSP_CTRL_CROSS : PSP_CTRL_CIRCLE;
  UiMetric.CancelButton = (!Options.ControlMode) ? PSP_CTRL_CIRCLE : PSP_CTRL_CROSS;
  UiMetric.ScrollbarColor = PSP_COLOR_GRAY;
  UiMetric.ScrollbarBgColor = 0x44ffffff;
  UiMetric.ScrollbarWidth = 10;
  UiMetric.TextColor = PSP_COLOR_GRAY;
  UiMetric.SelectedColor = PSP_COLOR_YELLOW;
  UiMetric.SelectedBgColor = COLOR(0xff,0xff,0xff,0x44);
  UiMetric.StatusBarColor = PSP_COLOR_WHITE;
  UiMetric.BrowserFileColor = PSP_COLOR_GRAY;
  UiMetric.BrowserDirectoryColor = PSP_COLOR_YELLOW;
  UiMetric.GalleryIconsPerRow = 5;
  UiMetric.GalleryIconMarginWidth = 8;
  UiMetric.MenuItemMargin = 20;
  UiMetric.MenuSelOptionBg = PSP_COLOR_BLACK;
  UiMetric.MenuOptionBoxColor = PSP_COLOR_GRAY;
  UiMetric.MenuOptionBoxBg = COLOR(0, 0, 33, 0xBB);
  UiMetric.MenuDecorColor = PSP_COLOR_YELLOW;
  UiMetric.DialogFogColor = COLOR(0, 0, 0, 88);
  UiMetric.TitlePadding = 4;

  UiMetric.TitleColor = PSP_COLOR_WHITE;
  UiMetric.MenuFps = 30;
  UiMetric.TabBgColor = COLOR(0x74,0x74,0xbe,0xff);
  UiMetric.BrowserScreenshotPath = ScreenshotPath;
  UiMetric.BrowserScreenshotDelay = 30;
}
Example #2
0
int pl_vk_load(pl_vk_layout *layout,
               const char *data_path,
               const char *image_path,
               int(*read_callback)(unsigned int),
               void(*write_callback)(unsigned int, int))
{
  /* Reset physical button status */
  int i;
  for (i = 0; _button_map[i]; i++)
    _push_time[i] = 0;

  /* Initialize */
  layout->keys = NULL;
  layout->stickies = NULL;
  layout->keyb_image = NULL;
  layout->key_count = layout->sticky_count =
    layout->offset_x = layout->offset_y =
    layout->selected = layout->held_down = 0;

  /* Load image */
  if (image_path && !(layout->keyb_image = pspImageLoadPng(image_path)))
    return 0;

  /* Init callbacks */
  layout->read_callback = read_callback;
  layout->write_callback = write_callback;

  /* Try opening file */
  FILE *file;
  if (!(file = fopen(data_path, "r")))
  {
    pl_vk_destroy(layout);
    return 0;
  }

  int code;
  uint16_t x, y, w, h;

  /* Determine button count */
  while ((fscanf(file, "0x%x\t%hi\t%hi\t%hi\t%hi\n",
                &code, &x, &y, &w, &h) == 5) && code)
    layout->key_count++;

  /* Rewind to start */
  rewind(file);

  layout->keys = (pl_vk_button*)malloc(layout->key_count *
                                       sizeof(pl_vk_button));
  if (!layout->keys)
  {
    fclose(file);
    pl_vk_destroy(layout);
    return 0;
  }

  /* Start reading keys */
  pl_vk_button *button;
  for (i = 0, button = layout->keys; i < layout->key_count; i++, button++)
  {
    if (fscanf(file, "0x%x\t%hi\t%hi\t%hi\t%hi\n",
               &code, &x, &y, &w, &h) < 5)
    {
      fclose(file);
      pl_vk_destroy(layout);
      return 0;
    }

    button->code = code & 0xffff;
    button->x = x;
    button->y = y;
    button->w = w;
    button->h = h;
    button->is_sticky = 0;
  }

  /* "Swallow" last record */
  fscanf(file, "0x%x\t%hi\t%hi\t%hi\t%hi\n",
         &code, &x, &y, &w, &h);

  /* Determine sticky count */
  long pos = ftell(file);
  while ((fscanf(file, "0x%x\t", &code) == 1) && code)
    layout->sticky_count++;

  /* Rewind again */
  fseek(file, pos, SEEK_SET);

  if (layout->sticky_count > 0)
  {
    layout->stickies = (pl_vk_sticky*)malloc(layout->sticky_count *
                                             sizeof(pl_vk_sticky));
    if (!layout->stickies)
    {
      fclose(file);
      pl_vk_destroy(layout);
      return 0;
    }

    /* Start reading stickies */
    pl_vk_sticky *sticky;
    for (i = 0, sticky = layout->stickies; i < layout->sticky_count; i++, sticky++)
    {
      if (fscanf(file, "0x%x\t", &code) < 1)
      {
        fclose(file);
        pl_vk_destroy(layout);
        return 0;
      }

      sticky->code = code & 0xffff;
      sticky->status = 0;
      sticky->index_count = 0;
      sticky->key_index = NULL;

      int j;
      for (j = 0; j < layout->key_count; j++)
      {
        /* Mark sticky status */
        if (layout->keys[j].code == sticky->code)
          layout->keys[j].is_sticky = 1;

        /* Determine number of matching sticky keys */
        if (layout->keys[j].code == sticky->code)
          sticky->index_count++;
      }

      /* Allocate space */
      if (sticky->index_count > 0)
      {
        sticky->key_index = (uint16_t*)malloc(sticky->index_count *
                                                    sizeof(uint16_t));
        if (!sticky->index_count)
        {
          fclose(file);
          pl_vk_destroy(layout);
          return 0;
        }
      }

      /* Save indices */
      int count;
      for (j = 0, count = 0; j < layout->key_count; j++)
        if (layout->keys[j].code == sticky->code)
          sticky->key_index[count++] = j;
    }
  }

  /* "Swallow" last record */
  fscanf(file, "0x%x\t", &code);

  /* Read the offsets */
  if (fscanf(file, "%hi\t%hi\n",
             &layout->offset_x, &layout->offset_y) < 2)
  {
    fclose(file);
    pl_vk_destroy(layout);
    return 0;
  }

  render_to_display_list(layout);

  /* Close the file */
  fclose(file);
  return 1;
}