void input_config_parse_key(config_file_t *conf, const char *prefix, const char *btn, struct retro_keybind *bind) { char tmp[64]; char key[64]; snprintf(key, sizeof(key), "%s_%s", prefix, btn); if (config_get_array(conf, key, tmp, sizeof(tmp))) bind->key = input_translate_str_to_rk(tmp); }
static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, struct overlay_desc *desc, unsigned ol_index, unsigned desc_index, unsigned width, unsigned height, bool normalized, float alpha_mod, float range_mod) { bool ret = true; char overlay_desc_key[64]; snprintf(overlay_desc_key, sizeof(overlay_desc_key), "overlay%u_desc%u", ol_index, desc_index); char overlay_desc_image_key[64]; snprintf(overlay_desc_image_key, sizeof(overlay_desc_image_key), "overlay%u_desc%u_overlay", ol_index, desc_index); char image_path[PATH_MAX]; if (config_get_path(conf, overlay_desc_image_key, image_path, sizeof(image_path))) { char path[PATH_MAX]; fill_pathname_resolve_relative(path, ol->overlay_path, image_path, sizeof(path)); struct texture_image img = {0}; if (texture_image_load(&img, path)) desc->image = img; } char overlay_desc_normalized_key[64]; snprintf(overlay_desc_normalized_key, sizeof(overlay_desc_normalized_key), "overlay%u_desc%u_normalized", ol_index, desc_index); config_get_bool(conf, overlay_desc_normalized_key, &normalized); bool by_pixel = !normalized; if (by_pixel && (width == 0 || height == 0)) { RARCH_ERR("[Overlay]: Base overlay is not set and not using normalized coordinates.\n"); return false; } char overlay[256]; if (!config_get_array(conf, overlay_desc_key, overlay, sizeof(overlay))) { RARCH_ERR("[Overlay]: Didn't find key: %s.\n", overlay_desc_key); return false; } struct string_list *list = string_split(overlay, ", "); if (!list) { RARCH_ERR("[Overlay]: Failed to split overlay desc.\n"); return false; } if (list->size < 6) { string_list_free(list); RARCH_ERR("[Overlay]: Overlay desc is invalid. Requires at least 6 tokens.\n"); return false; } const char *x = list->elems[1].data; const char *y = list->elems[2].data; const char *box = list->elems[3].data; char *key = list->elems[0].data; char *save; desc->key_mask = 0; if (strcmp(key, "analog_left") == 0) desc->type = OVERLAY_TYPE_ANALOG_LEFT; else if (strcmp(key, "analog_right") == 0) desc->type = OVERLAY_TYPE_ANALOG_RIGHT; else if (strstr(key, "retrok_") == key) { desc->type = OVERLAY_TYPE_KEYBOARD; desc->key_mask = input_translate_str_to_rk(key + 7); } else { const char *tmp; desc->type = OVERLAY_TYPE_BUTTONS; for (tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save)) { if (strcmp(tmp, "nul") != 0) desc->key_mask |= UINT64_C(1) << input_translate_str_to_bind_id(tmp); } if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT)) { char overlay_target_key[64]; snprintf(overlay_target_key, sizeof(overlay_target_key), "overlay%u_desc%u_next_target", ol_index, desc_index); config_get_array(conf, overlay_target_key, desc->next_index_name, sizeof(desc->next_index_name)); } } float width_mod = by_pixel ? (1.0f / width) : 1.0f; float height_mod = by_pixel ? (1.0f / height) : 1.0f; desc->x = (float)strtod(x, NULL) * width_mod; desc->y = (float)strtod(y, NULL) * height_mod; if (!strcmp(box, "radial")) desc->hitbox = OVERLAY_HITBOX_RADIAL; else if (!strcmp(box, "rect")) desc->hitbox = OVERLAY_HITBOX_RECT; else { RARCH_ERR("[Overlay]: Hitbox type (%s) is invalid. Use \"radial\" or \"rect\".\n", box); ret = false; goto end; } if (desc->type == OVERLAY_TYPE_ANALOG_LEFT || desc->type == OVERLAY_TYPE_ANALOG_RIGHT) { if (desc->hitbox != OVERLAY_HITBOX_RADIAL) { RARCH_ERR("[Overlay]: Analog hitbox type must be \"radial\".\n"); ret = false; goto end; } char overlay_analog_saturate_key[64]; snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key), "overlay%u_desc%u_saturate_pct", ol_index, desc_index); if (!config_get_float(conf, overlay_analog_saturate_key, &desc->analog_saturate_pct)) desc->analog_saturate_pct = 1.0f; } desc->range_x = (float)strtod(list->elems[4].data, NULL) * width_mod; desc->range_y = (float)strtod(list->elems[5].data, NULL) * height_mod; desc->mod_x = desc->x - desc->range_x; desc->mod_w = 2.0f * desc->range_x; desc->mod_y = desc->y - desc->range_y; desc->mod_h = 2.0f * desc->range_y; char conf_key[64]; snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_alpha_mod", ol_index, desc_index); desc->alpha_mod = alpha_mod; config_get_float(conf, conf_key, &desc->alpha_mod); snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_range_mod", ol_index, desc_index); desc->range_mod = range_mod; config_get_float(conf, conf_key, &desc->range_mod); snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_movable", ol_index, desc_index); desc->movable = false; desc->delta_x = 0.0f; desc->delta_y = 0.0f; config_get_bool(conf, conf_key, &desc->movable); desc->range_x_mod = desc->range_x; desc->range_y_mod = desc->range_y; end: if (list) string_list_free(list); return ret; }