コード例 #1
0
ファイル: input_overlay.c プロジェクト: maddox/RetroArch
static bool input_overlay_load_overlay(input_overlay_t *ol,
      const char *config_path,
      struct overlay *overlay, unsigned idx)
{
   size_t i;

   for (i = 0; i < overlay->pos_increment; i++)
   {
      bool not_done = overlay->pos < overlay->size;
      if (!not_done)
      {
         overlay->pos   = 0;
         ol->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_DONE;
         return true;
      }

      if (!input_overlay_load_desc(ol, &overlay->descs[overlay->pos], idx, overlay->pos,
               overlay->image.width, overlay->image.height,
               overlay->config.normalized,
               overlay->config.alpha_mod, overlay->config.range_mod))
      {
         RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n",
               (unsigned)overlay->pos);
         goto error;
      }

      if (overlay->descs[overlay->pos].image.pixels)
      {
         overlay->descs[overlay->pos].image_index = overlay->load_images_size;
         overlay->load_images[overlay->load_images_size++] = overlay->descs[overlay->pos].image;
      }
      overlay->pos ++;
   }

   return true;

error:
   return false;
}
コード例 #2
0
ファイル: overlay.c プロジェクト: ChowZenki/RetroArch
static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf, const char *config_path,
      struct overlay *overlay, unsigned index)
{
   size_t i;
   char overlay_path_key[64];
   char overlay_name_key[64];
   char overlay_path[PATH_MAX];
   char overlay_resolved_path[PATH_MAX];

   snprintf(overlay_path_key, sizeof(overlay_path_key), "overlay%u_overlay", index);
   if (config_get_path(conf, overlay_path_key, overlay_path, sizeof(overlay_path)))
   {
      struct texture_image img = {0};

      fill_pathname_resolve_relative(overlay_resolved_path, config_path,
            overlay_path, sizeof(overlay_resolved_path));

      if (texture_image_load(&img, overlay_resolved_path))
         overlay->image = img;
      else
      {
         RARCH_ERR("[Overlay]: Failed to load image: %s.\n", overlay_resolved_path);
         return false;
      }
   }

   snprintf(overlay_name_key, sizeof(overlay_name_key), "overlay%u_name", index);
   config_get_array(conf, overlay_name_key, overlay->name, sizeof(overlay->name));

   // By default, we stretch the overlay out in full.
   overlay->x = overlay->y = 0.0f;
   overlay->w = overlay->h = 1.0f;

   char overlay_rect_key[64];
   snprintf(overlay_rect_key, sizeof(overlay_rect_key), "overlay%u_rect", index);
   char overlay_rect[256];
   if (config_get_array(conf, overlay_rect_key, overlay_rect, sizeof(overlay_rect)))
   {
      struct string_list *list = string_split(overlay_rect, ", ");
      if (list->size < 4)
      {
         RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay_rect);
         return false;
      }

      overlay->x = (float)strtod(list->elems[0].data, NULL);
      overlay->y = (float)strtod(list->elems[1].data, NULL);
      overlay->w = (float)strtod(list->elems[2].data, NULL);
      overlay->h = (float)strtod(list->elems[3].data, NULL);
      string_list_free(list);
   }

   char overlay_full_screen_key[64];
   snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key),
         "overlay%u_full_screen", index);
   overlay->full_screen = false;
   config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen);

   char overlay_descs_key[64];
   snprintf(overlay_descs_key, sizeof(overlay_descs_key), "overlay%u_descs", index);

   unsigned descs = 0;
   if (!config_get_uint(conf, overlay_descs_key, &descs))
   {
      RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay_descs_key);
      return false;
   }

   overlay->descs = (struct overlay_desc*)calloc(descs, sizeof(*overlay->descs));
   if (!overlay->descs)
   {
      RARCH_ERR("[Overlay]: Failed to allocate descs.\n");
      return false;
   }

   overlay->size = descs;

   char conf_key[64];
   bool normalized = false;
   snprintf(conf_key, sizeof(conf_key),
         "overlay%u_normalized", index);
   config_get_bool(conf, conf_key, &normalized);

   float alpha_mod = 1.0f;
   snprintf(conf_key, sizeof(conf_key), "overlay%u_alpha_mod", index);
   config_get_float(conf, conf_key, &alpha_mod);

   float range_mod = 1.0f;
   snprintf(conf_key, sizeof(conf_key), "overlay%u_range_mod", index);
   config_get_float(conf, conf_key, &range_mod);

   for (i = 0; i < overlay->size; i++)
   {
      if (!input_overlay_load_desc(ol, conf, &overlay->descs[i], index, i,
               overlay->image.width, overlay->image.height,
               normalized, alpha_mod, range_mod))
      {
         RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n", (unsigned)i);
         return false;
      }
   }

   // Precache load image array for simplicity.
   overlay->load_images = (struct texture_image*)calloc(1 + overlay->size, sizeof(struct texture_image));
   if (!overlay->load_images)
   {
      RARCH_ERR("[Overlay]: Failed to allocate load_images.\n");
      return false;
   }

   if (overlay->image.pixels)
      overlay->load_images[overlay->load_images_size++] = overlay->image;

   for (i = 0; i < overlay->size; i++)
   {
      if (overlay->descs[i].image.pixels)
      {
         overlay->descs[i].image_index = overlay->load_images_size;
         overlay->load_images[overlay->load_images_size++] = overlay->descs[i].image;
      }
   }

   // Assume for now that scaling center is in the middle.
   // TODO: Make this configurable.
   overlay->block_scale = false;
   overlay->center_x = overlay->x + 0.5f * overlay->w;
   overlay->center_y = overlay->y + 0.5f * overlay->h;

   return true;
}
コード例 #3
0
ファイル: overlay.c プロジェクト: DukedDroid/RetroArch
static bool input_overlay_load_overlay(config_file_t *conf, const char *config_path,
      struct overlay *overlay, unsigned index)
{
   char overlay_path_key[64];
   char overlay_name_key[64];
   char overlay_path[PATH_MAX];
   char overlay_resolved_path[PATH_MAX];

   snprintf(overlay_path_key, sizeof(overlay_path_key), "overlay%u_overlay", index);
   if (!config_get_path(conf, overlay_path_key, overlay_path, sizeof(overlay_path)))
   {
      RARCH_ERR("[Overlay]: Config key: %s is not set.\n", overlay_path_key);
      return false;
   }

   snprintf(overlay_name_key, sizeof(overlay_name_key), "overlay%u_name", index);
   config_get_array(conf, overlay_name_key, overlay->name, sizeof(overlay->name));

   fill_pathname_resolve_relative(overlay_resolved_path, config_path,
         overlay_path, sizeof(overlay_resolved_path));

   struct texture_image img = {0};
   if (!texture_image_load(overlay_resolved_path, &img))
   {
      RARCH_ERR("Failed to load image: %s.\n", overlay_path);
      return false;
   }

   overlay->image  = img.pixels;
   overlay->width  = img.width;
   overlay->height = img.height;

   // By default, we stretch the overlay out in full.
   overlay->x = overlay->y = 0.0f;
   overlay->w = overlay->h = 1.0f;

   char overlay_rect_key[64];
   snprintf(overlay_rect_key, sizeof(overlay_rect_key), "overlay%u_rect", index);
   char overlay_rect[256];
   if (config_get_array(conf, overlay_rect_key, overlay_rect, sizeof(overlay_rect)))
   {
      struct string_list *list = string_split(overlay_rect, ", ");
      if (list->size < 4)
      {
         RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay_rect);
         return false;
      }

      overlay->x = strtod(list->elems[0].data, NULL);
      overlay->y = strtod(list->elems[1].data, NULL);
      overlay->w = strtod(list->elems[2].data, NULL);
      overlay->h = strtod(list->elems[3].data, NULL);
      string_list_free(list);
   }

   char overlay_full_screen_key[64];
   snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key),
         "overlay%u_full_screen", index);
   overlay->full_screen = false;
   config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen);

   char overlay_descs_key[64];
   snprintf(overlay_descs_key, sizeof(overlay_descs_key), "overlay%u_descs", index);

   unsigned descs = 0;
   if (!config_get_uint(conf, overlay_descs_key, &descs))
   {
      RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay_descs_key);
      return false;
   }

   overlay->descs = (struct overlay_desc*)calloc(descs, sizeof(*overlay->descs));
   if (!overlay->descs)
   {
      RARCH_ERR("[Overlay]: Failed to allocate descs.\n");
      return false;
   }

   overlay->size = descs;

   for (size_t i = 0; i < overlay->size; i++)
   {
      if (!input_overlay_load_desc(conf, &overlay->descs[i], index, i, img.width, img.height))
      {
         RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n", (unsigned)i);
         return false;
      }
   }


   // Assume for now that scaling center is in the middle.
   // TODO: Make this configurable.
   overlay->block_scale = false;
   overlay->center_x = overlay->x + 0.5f * overlay->w;
   overlay->center_y = overlay->y + 0.5f * overlay->h;

   return true;
}