void drawListDialog() { if (is_open == LIST_DIALOG_CLOSE) return; // Dialog background vita2d_draw_texture_scale_rotate_hotspot(dialog_image, list_dialog.x + list_dialog.width / 2.0f, list_dialog.y + list_dialog.height / 2.0f, list_dialog.scale * (list_dialog.width / vita2d_texture_get_width(dialog_image)), list_dialog.scale * (list_dialog.height / vita2d_texture_get_height(dialog_image)), 0.0f, vita2d_texture_get_width(dialog_image) / 2.0f, vita2d_texture_get_height(dialog_image) / 2.0f); // Easing out if (list_dialog.animation_mode == LIST_DIALOG_CLOSING) { if (list_dialog.scale > 0.0f) { list_dialog.scale -= easeOut3(0.0f, list_dialog.scale, 0.25f); } else { list_dialog.animation_mode = LIST_DIALOG_CLOSED; list_dialog.status = SCE_COMMON_DIALOG_STATUS_FINISHED; } } if (list_dialog.animation_mode == LIST_DIALOG_OPENING) { if (list_dialog.scale < 1.0f) { list_dialog.scale += easeOut3(list_dialog.scale, 1.0f, 0.25f); } else { list_dialog.animation_mode = LIST_DIALOG_OPENED; } } if (list_dialog.animation_mode == LIST_DIALOG_OPENED) { pgf_draw_text(list_dialog.x + ALIGN_CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->title])), list_dialog.y + FONT_Y_SPACE, TEXT_COLOR, FONT_SIZE, language_container[current_list->title]); int z; for (z = 0;z < LIST_MAX_ENTRY && (base_pos + z) < current_list->n_list_entries; z++) { uint32_t color = (rel_pos == z) ? TEXT_FOCUS_COLOR : TEXT_COLOR; pgf_draw_text(list_dialog.x + ALIGN_CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->list_entries[(z + base_pos)].name])), list_dialog.y + (FONT_Y_SPACE * 3) + (FONT_Y_SPACE * z), color, FONT_SIZE, language_container[current_list->list_entries[(z + base_pos)].name]); } int max_base_pos = current_list->n_list_entries - LIST_MAX_ENTRY; if (base_pos < max_base_pos && current_list->n_list_entries > LIST_MAX_ENTRY) { pgf_draw_text(list_dialog.x + ALIGN_CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, DOWN_ARROW)), list_dialog.y + (FONT_Y_SPACE * 3) + (FONT_Y_SPACE * max_entry_show), TEXT_COLOR, FONT_SIZE, DOWN_ARROW); } if (base_pos > 0 && current_list->n_list_entries > LIST_MAX_ENTRY) { pgf_draw_text(list_dialog.x + ALIGN_CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, UP_ARROW)), list_dialog.y + (FONT_Y_SPACE * 2), TEXT_COLOR, FONT_SIZE, UP_ARROW); } } else if (list_dialog.animation_mode == LIST_DIALOG_CLOSED) { if (list_dialog.enter_pressed) { if (current_list->listSelectCallback) current_list->listSelectCallback(base_pos + rel_pos); } is_open = LIST_DIALOG_CLOSE; } }
static int atlas_add_glyph_pgf(vita2d_pgf *font, unsigned int character) { SceFontCharInfo char_info; if (sceFontGetCharInfo(font->font_handle, character, &char_info) < 0) return 0; int pos_x; int pos_y; if (!texture_atlas_insert(font->tex_atlas, character, char_info.bitmapWidth, char_info.bitmapHeight, char_info.bitmapLeft, char_info.bitmapTop, char_info.sfp26AdvanceH, char_info.sfp26AdvanceV, 0, &pos_x, &pos_y)) return 0; vita2d_texture *tex = font->tex_atlas->tex; SceFontGlyphImage glyph_image; glyph_image.pixelFormat = SCE_FONT_PIXELFORMAT_8; glyph_image.xPos64 = pos_x << 6; glyph_image.yPos64 = pos_y << 6; glyph_image.bufWidth = vita2d_texture_get_width(tex); glyph_image.bufHeight = vita2d_texture_get_height(tex); glyph_image.bytesPerLine = vita2d_texture_get_stride(tex); glyph_image.pad = 0; glyph_image.bufferPtr = (unsigned int)vita2d_texture_get_datap(tex); return sceFontGetCharGlyphImage(font->font_handle, character, &glyph_image) == 0; }
int texture_atlas_insert(texture_atlas *atlas, unsigned int character, const void *image, int width, int height, int bitmap_left, int bitmap_top, int advance_x, int advance_y, int glyph_size) { bp2d_size size; size.w = width; size.h = height; bp2d_position pos; if (bp2d_insert(atlas->bp_root, &size, &pos) == 0) return 0; atlas_htab_entry *entry = malloc(sizeof(*entry)); entry->rect.x = pos.x; entry->rect.y = pos.y; entry->rect.w = width; entry->rect.h = height; entry->bitmap_left = bitmap_left; entry->bitmap_top = bitmap_top; entry->advance_x = advance_x; entry->advance_y = advance_y; entry->glyph_size = glyph_size; int_htab_insert(atlas->htab, character, entry); void *tex_data = vita2d_texture_get_datap(atlas->tex); unsigned int tex_width = vita2d_texture_get_width(atlas->tex); int i; for (i = 0; i < height; i++) { memcpy(tex_data + (pos.x + (pos.y + i)*tex_width), image + i*width, width); } return 1; }
static int atlas_add_glyph(vita2d_pgf *font, unsigned int character) { SceFontHandle font_handle = font->font_handle_list->font_handle; SceFontCharInfo char_info; bp2d_position position; void *texture_data; vita2d_texture *tex = font->atlas->texture; vita2d_pgf_font_handle *tmp = font->font_handle_list; while (tmp) { if (tmp->in_font_group == NULL || tmp->in_font_group(character)) { font_handle = tmp->font_handle; break; } tmp = tmp->next; } if (sceFontGetCharInfo(font_handle, character, &char_info) < 0) return 0; bp2d_size size = { char_info.bitmapWidth, char_info.bitmapHeight }; texture_atlas_entry_data data = { char_info.bitmapLeft, char_info.bitmapTop, char_info.sfp26AdvanceH, char_info.sfp26AdvanceV, 0 }; if (!texture_atlas_insert(font->atlas, character, &size, &data, &position)) return 0; texture_data = vita2d_texture_get_datap(tex); SceFontGlyphImage glyph_image; glyph_image.pixelFormat = SCE_FONT_PIXELFORMAT_8; glyph_image.xPos64 = position.x << 6; glyph_image.yPos64 = position.y << 6; glyph_image.bufWidth = vita2d_texture_get_width(tex); glyph_image.bufHeight = vita2d_texture_get_height(tex); glyph_image.bytesPerLine = vita2d_texture_get_stride(tex); glyph_image.pad = 0; glyph_image.bufferPtr = (unsigned int)texture_data; return sceFontGetCharGlyphImage(font_handle, character, &glyph_image) == 0; }
int drawUncommonDialog() { if (uncommon_dialog.status == SCE_COMMON_DIALOG_STATUS_NONE) return 0; // Dialog background vita2d_draw_texture_scale_rotate_hotspot(dialog_image, uncommon_dialog.x + uncommon_dialog.width / 2.0f, uncommon_dialog.y + uncommon_dialog.height / 2.0f, uncommon_dialog.scale * (uncommon_dialog.width / vita2d_texture_get_width(dialog_image)), uncommon_dialog.scale * (uncommon_dialog.height / vita2d_texture_get_height(dialog_image)), 0.0f, vita2d_texture_get_width(dialog_image) / 2.0f, vita2d_texture_get_height(dialog_image) / 2.0f); // Easing out if (uncommon_dialog.dialog_status == UNCOMMON_DIALOG_CLOSING) { if (uncommon_dialog.scale > 0.0f) { uncommon_dialog.scale -= easeOut(0.0f, uncommon_dialog.scale, 0.25f); } else { uncommon_dialog.dialog_status = UNCOMMON_DIALOG_CLOSED; uncommon_dialog.status = SCE_COMMON_DIALOG_STATUS_FINISHED; } } if (uncommon_dialog.dialog_status == UNCOMMON_DIALOG_OPENING) { if (uncommon_dialog.scale < 1.0f) { uncommon_dialog.scale += easeOut(uncommon_dialog.scale, 1.0f, 0.25f); } else { uncommon_dialog.dialog_status = UNCOMMON_DIALOG_OPENED; } } if (uncommon_dialog.dialog_status == UNCOMMON_DIALOG_OPENED) { // Draw message float string_y = uncommon_dialog.y + SHELL_MARGIN_Y - 2.0f; int len = strlen(uncommon_dialog.msg); char *string = uncommon_dialog.msg; int i; for (i = 0; i < len + 1; i++) { if (uncommon_dialog.msg[i] == '\n') { uncommon_dialog.msg[i] = '\0'; pgf_draw_text(uncommon_dialog.x + SHELL_MARGIN_X, string_y, DIALOG_COLOR, FONT_SIZE, string); uncommon_dialog.msg[i] = '\n'; string = uncommon_dialog.msg + i + 1; string_y += FONT_Y_SPACE; } if (uncommon_dialog.msg[i] == '\0') { pgf_draw_text(uncommon_dialog.x + SHELL_MARGIN_X, string_y, DIALOG_COLOR, FONT_SIZE, string); string_y += FONT_Y_SPACE; } } // Dialog type char button_string[32]; switch (uncommon_dialog.buttonType) { case SCE_MSG_DIALOG_BUTTON_TYPE_OK: sprintf(button_string, "%s %s", enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CIRCLE : CROSS, language_container[OK]); break; case SCE_MSG_DIALOG_BUTTON_TYPE_YESNO: sprintf(button_string, "%s %s %s %s", enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CIRCLE : CROSS, language_container[YES], enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CROSS : CIRCLE, language_container[NO]); break; case SCE_MSG_DIALOG_BUTTON_TYPE_OK_CANCEL: sprintf(button_string, "%s %s %s %s", enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CIRCLE : CROSS, language_container[OK], enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CROSS : CIRCLE, language_container[CANCEL]); break; case SCE_MSG_DIALOG_BUTTON_TYPE_CANCEL: sprintf(button_string, "%s %s", enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE ? CROSS : CIRCLE, language_container[CANCEL]); break; } // Progress bar if (uncommon_dialog.mode == SCE_MSG_DIALOG_MODE_PROGRESS_BAR) { float width = uncommon_dialog.width - 2.0f * SHELL_MARGIN_X; vita2d_draw_rectangle(uncommon_dialog.x + SHELL_MARGIN_X, string_y + 10.0f, width, UNCOMMON_DIALOG_PROGRESS_BAR_HEIGHT, PROGRESS_BAR_BG_COLOR); vita2d_draw_rectangle(uncommon_dialog.x + SHELL_MARGIN_X, string_y + 10.0f, uncommon_dialog.progress * width / 100.0f, UNCOMMON_DIALOG_PROGRESS_BAR_HEIGHT, PROGRESS_BAR_COLOR); char string[8]; sprintf(string, "%d%%", uncommon_dialog.progress); pgf_draw_text(ALIGN_CENTER(SCREEN_WIDTH, vita2d_pgf_text_width(font, FONT_SIZE, string)), string_y + FONT_Y_SPACE, DIALOG_COLOR, FONT_SIZE, string); string_y += 2.0f * FONT_Y_SPACE; } switch (uncommon_dialog.buttonType) { case SCE_MSG_DIALOG_BUTTON_TYPE_OK: case SCE_MSG_DIALOG_BUTTON_TYPE_YESNO: case SCE_MSG_DIALOG_BUTTON_TYPE_OK_CANCEL: case SCE_MSG_DIALOG_BUTTON_TYPE_CANCEL: pgf_draw_text(ALIGN_CENTER(SCREEN_WIDTH, vita2d_pgf_text_width(font, FONT_SIZE, button_string)), string_y + FONT_Y_SPACE, DIALOG_COLOR, FONT_SIZE, button_string); break; } } return 0; }