void SoFont_CenteredString_XY (SoFont * font, SDL_Surface * Surface, int x, int y, const char *text, SDL_Rect * clip) { if (!font->picture) return; SoFont_PutString (font, Surface, x - SoFont_TextWidth (font, text) / 2, y - font->height / 2, text, clip); }
void SoFont_XCenteredString (SoFont * font, SDL_Surface * Surface, int y, const char *text, SDL_Rect * clip) { if (!font->picture) return; SoFont_PutString (font, Surface, Surface->w / 2 - SoFont_TextWidth (font, text) / 2, y, text, clip); }
void SoFont_PutStringWithCursor (SoFont * font, SDL_Surface * Surface, int xs,int y, const char *text, int cursPos,SDL_Rect * clip, int showCurs) { int ofs, i = 0, x = xs; SDL_Rect srcrect, dstrect; if ((!font->picture) || (!Surface) || (!text)) return; if ('|' > font->max_i) showCurs = 0; // We want the cursor to appear under the main text. if (showCurs) { while (text[i] != '\0') if (i == cursPos) break; else if (text[i] == ' ') { x += font->spacew; i++; } else if ((text[i] >= START_CHAR) && (text[i] <= font->max_i)) { ofs = text[i] - START_CHAR; x += font->Spacing[ofs]; i++; } else i++; ofs = '|' - START_CHAR; srcrect.w = dstrect.w = font->CharPos[ofs + 1] - font->CharPos[ofs]; srcrect.h = dstrect.h = font->height; srcrect.x = font->CharPos[ofs]; srcrect.y = 1; dstrect.x = x - font->cursShift; dstrect.y = y; if (clip) sdcRects (&srcrect, &dstrect, *clip); SDL_BlitSurface (font->picture->surf, &srcrect, Surface, &dstrect); } // Then the text: SoFont_PutString (font, Surface, xs, y, text, clip); }
void menu_draw (Menu * menu, SDL_Surface * surf) { if (menu->visible) { int c; // compteur d'items int center = surf->w / 2; int hauteur = (surf->h - menu->hauteur) / 2; hauteur += menu->hide; for (c = 0; c < menu->nb_items; c++) { SDL_Surface *item_surf = menu->items[c].bitmap; SoFont *item_font = menu->items[c].font; if (item_surf || item_font) { int center_x; center_x = (int)(center + menu->items[c].priv_x); if (item_surf != NULL) { SDL_Rect rect; rect.x = center_x - item_surf->w / 2; rect.y = hauteur; rect.w = item_surf->w; rect.h = item_surf->h; SDL_BlitSurface (item_surf, NULL, surf, &rect); hauteur += item_surf->h; } else { // font.. static char item_name[1024]; if (c == menu->active_item) { SDL_Rect rect; if (menu->menuselector==NULL) { rect.x = center - 140; rect.w = 280; rect.y = hauteur; rect.h = SoFont_FontHeight (item_font); SDL_FillRect (surf, &rect, 0); rect.x = center - 150; rect.w = 300; rect.y = hauteur + 3; rect.h = SoFont_FontHeight (item_font) - 6; SDL_FillRect (surf, &rect, 0); } else { rect.x = center - 150; rect.w = menu->menuselector->w; rect.y = hauteur - 3; rect.h = menu->menuselector->h; SDL_BlitSurface (menu->menuselector->surf, NULL, surf, &rect); } } strcpy (item_name, menu->items[c].name); if (menu->items[c].value) { strcat (item_name, menu->items[c].value); } char *pc = item_name; int nbTab = 0; for (; *pc; pc++) { if (*pc == '\t') { while (*pc == '\t') { *pc = 0; pc ++; nbTab ++; } break; } } if (nbTab > 0) { int w = 80 + nbTab * 50; SoFont_PutString (item_font, surf, center_x-w, hauteur, item_name, NULL); SoFont_PutString (item_font, surf, center_x+w - SoFont_TextWidth(item_font, pc), hauteur, pc, NULL); } else { SoFont_PutString (item_font, surf, center_x - SoFont_TextWidth (item_font, item_name) / 2, hauteur, item_name, NULL); } hauteur += SoFont_FontHeight (item_font); } } else hauteur += menu->sep_size; } } }