/* draw text over multiple lines if it's length exceeds maxlen */ void vultures_put_text_multiline(int font_id, const char *str, SDL_Surface *dest, int x, int y, Uint32 color, Uint32 shadowcolor, int maxlen) { char *str_copy; int lastfit, txtlen, lineno, text_height, endpos, startpos; lineno = 0; lastfit = 0; startpos = endpos = 0; text_height = vultures_text_height(font_id, str); /* lastfit is true when the last segment has been fit onto the surface (drawn) */ while (!lastfit) { lastfit = 1; startpos = startpos + endpos; str_copy = strdup(str + startpos); endpos = strlen(str_copy) - 1; txtlen = vultures_text_length(font_id, str_copy); /* split word off the end of the string until it is short enough to fit */ while (txtlen > maxlen) { /* a piece will be split off the end, so this is not the last piece */ lastfit = 0; /* find a suitable place to split */ while (endpos && !isspace(str_copy[endpos])) endpos--; /* prevent infinite loops if a long word doesn't fit */ if (endpos == 0) { endpos = strlen(str_copy) - 1; lastfit = 1; break; } /* truncate the text */ str_copy[endpos++] = '\0'; txtlen = vultures_text_length(font_id, str_copy); } vultures_put_text_shadow(font_id, str_copy, dest, x, y + lineno * text_height, color, shadowcolor); free(str_copy); lineno++; } }
bool objheaderwin::draw() { /* constrain drawing to this window */ vultures_set_draw_region(abs_x, abs_y, abs_x + w - 1, abs_y + h - 1); vultures_fill_rect(abs_x + 2, abs_y + 2, abs_x + w - 3, abs_y + h - 3, CLR32_BLACK_A50); /* Outer edge */ vultures_draw_lowered_frame(abs_x, abs_y, abs_x+w-1, abs_y+h-1); /* Inner edge */ vultures_draw_raised_frame(abs_x+1, abs_y+1, abs_x+w-2, abs_y+h-2); /* draw the text centered in the window */ int txt_width = vultures_text_length(V_FONT_MENU, caption); int txt_height = vultures_text_height(V_FONT_MENU, caption); int text_start_x = abs_x + (w - txt_width)/2; int text_start_y = abs_y + (h - txt_height)/2; vultures_put_text_shadow(V_FONT_MENU, caption, vultures_screen, text_start_x, text_start_y, CLR32_WHITE, CLR32_BLACK); vultures_invalidate_region(abs_x, abs_y, w, h); /* lift drawing region restriction */ vultures_set_draw_region(0, 0, vultures_screen->w - 1, vultures_screen->h - 1); return 0; }
bool map::draw() { int map_x, map_y; int i, j; window * txt = first_child; char buffer[256]; /* Draw parchment */ vultures_put_img(abs_x, abs_y, mapbg); /* Draw the level name */ #ifdef VULTURESCLAW describe_level(buffer, TRUE); #else if (!describe_level(buffer)) sprintf(buffer, "%s, level %d ", dungeons[u.uz.dnum].dname, depth(&u.uz)); #endif txt->set_caption(buffer); txt->x = (w - vultures_text_length(V_FONT_HEADLINE, txt->caption)) / 2; txt->abs_x = abs_x + txt->x; txt->abs_y = abs_y + txt->y; vultures_put_text_shadow(V_FONT_HEADLINE, txt->caption, vultures_screen, txt->abs_x, txt->abs_y, CLR32_BROWN, CLR32_BLACK_A50); /* Find upper left corner of map on parchment */ map_x = abs_x + 39; map_y = abs_y + 91; /* Draw map on parchment, and create hotspots */ for (i = 0; i < ROWNO; i++) for (j = 1; j < COLNO; j++) { int map_glyph = map_data->get_glyph(MAP_GLYPH, j, i); bool is_dark = (map_data->get_glyph(MAP_DARKNESS, j, i) == 2); if (map_glyph != NO_GLYPH && (map_glyph != cmap_to_glyph(S_stone) || (level.locations[j][i].seenv && is_dark))) { vultures_put_img( map_x + SYMBOL_WIDTH*j, map_y + SYMBOL_HEIGHT*i, map_symbols[glyph2tile[map_glyph]]); } } vultures_invalidate_region(abs_x, abs_y, w, h); return false; }
bool endingwin::draw() { int lines; int textpos_x, textpos_y; SDL_Surface *image; if (!flags.tombstone) { for (item_iterator i = items.begin(); i != items.end(); ++i) printf("%s\n", i->str.c_str()); printf("\n\n"); return false; } /* make sure the screen is cleared */ SDL_FillRect(vultures_screen, NULL, CLR32_BLACK); switch (ending_type-1) { case QUIT: image = vultures_load_graphic(V_FILENAME_ENDING_QUIT); vultures_play_event_sound("nhfe_music_end_quit"); break; case ASCENDED: image = vultures_load_graphic(V_FILENAME_ENDING_ASCENDED); vultures_play_event_sound("nhfe_music_end_ascended"); break; case ESCAPED: image = vultures_load_graphic(V_FILENAME_ENDING_ESCAPED); vultures_play_event_sound("nhfe_music_end_ascended"); break; case PANICKED: image = NULL; break; default: image = vultures_load_graphic(V_FILENAME_ENDING_DIED); vultures_play_event_sound("nhfe_music_end_died"); } if (image != NULL) { vultures_put_img((vultures_screen->w - image->w) / 2, (vultures_screen->h - image->h) / 2, image); SDL_FreeSurface(image); vultures_fade_in(0.5); } /* Count n. of rows to display */ lines = items.size(); /* Add prompt line */ lines++; /* Display the rows */ textpos_y = vultures_screen->h - (lines+1) * vultures_get_lineheight(V_FONT_INTRO); for (item_iterator i = items.begin(); i != items.end(); ++i) { textpos_x = (vultures_screen->w - vultures_text_length(V_FONT_INTRO, i->str))/2; vultures_put_text_shadow(V_FONT_INTRO, i->str, vultures_screen, textpos_x, textpos_y, V_COLOR_INTRO_TEXT, V_COLOR_BACKGROUND); textpos_y += vultures_get_lineheight(V_FONT_INTRO); } textpos_x = (vultures_screen->w - vultures_text_length(V_FONT_INTRO, "(press any key)"))/2; vultures_put_text_shadow(V_FONT_INTRO, "(press any key)", vultures_screen, textpos_x, textpos_y, V_COLOR_INTRO_TEXT, V_COLOR_BACKGROUND); vultures_refresh(); return false; }
bool objitemwin::draw() { char tmpstr[32]; int text_start_x, text_start_y, txt_height; int x = abs_x; int y = abs_y; int weight = 0; Uint32 textcolor; vultures_set_draw_region(x, y, x + w - 1, y + h - 1); /* re-set the background to prevent shadings from stacking repatedly until they become solid */ if (background) vultures_put_img(x, y, background); /* hovering gives an item a light blue frame */ if (hover) vultures_rect(x+1, y+1, x+w-2, y+h-2, CLR32_BLESS_BLUE); /* otherwise, if it is selected, the item has an orange frame */ else if (item->selected) vultures_rect(x+1, y+1, x+w-2, y+h-2, CLR32_ORANGE); /* all other items appear etched */ else { /* draw the outer edge of the frame */ vultures_draw_lowered_frame(x, y, x+w-1, y+h-1); /* Inner edge */ vultures_draw_raised_frame(x+1, y+1, x+w-2, y+h-2); } /* the item that was toggled last has a white outer frame to indicate it's special status */ if (last_toggled) vultures_rect(x, y, x+w-1, y+h-1, CLR32_WHITE); /* selected items also have yellow background shading */ if (item->selected) vultures_fill_rect(x+h-1, y+2, x+w-3, y+h-3, CLR32_GOLD_SHADE); /* use a different text color for worn objects */ if (obj && obj->owornmask) textcolor = CLR32_LIGHTGREEN; else textcolor = CLR32_WHITE; /* draw text, leaving a h by h square on the left free for the object tile */ /* line 1 and if necessary line 2 contain the item description */ vultures_put_text_multiline(V_FONT_MENU, caption, vultures_screen, x + h, y + 3, textcolor, CLR32_BLACK, w - h - 6); /* weight is in line 3 */ txt_height = vultures_text_height(V_FONT_MENU, caption); text_start_y = y + txt_height*2 + 4; /* draw the object weight */ tmpstr[0] = '\0'; if (weight) snprintf(tmpstr, 32, "w: %d", weight); text_start_x = x + (w - vultures_text_length(V_FONT_MENU, tmpstr))/2; vultures_put_text_shadow(V_FONT_MENU, tmpstr, vultures_screen, text_start_x, text_start_y, textcolor, CLR32_BLACK); if (item->selected) { tmpstr[0] = '\0'; if (item->count <= 0 || (obj && item->count > obj->quan)) snprintf(tmpstr, 32, "selected (all)"); else snprintf(tmpstr, 32, "selected (%d)", item->count); text_start_x = x + w - vultures_text_length(V_FONT_MENU, tmpstr) - 6; vultures_put_text_shadow(V_FONT_MENU, tmpstr, vultures_screen, text_start_x, text_start_y, textcolor, CLR32_BLACK); } /* draw the tile itself */ /* constrain the drawing region to the box for the object tile, so that large * tiles don't overlap */ vultures_set_draw_region(x + 2, y + 2, x + h - 3, y + h - 3); /* darken the background */ vultures_fill_rect(x + 2, y + 2, x + h - 3, y + h - 3, CLR32_BLACK_A30); /* indicate blessed/cursed visually */ if (obj && obj->bknown && obj->blessed) vultures_fill_rect(x + 2, y + 2, x + h - 3, y + h - 3, CLR32_BLESS_BLUE); if (obj && obj->bknown && obj->cursed) vultures_fill_rect(x + 2, y + 2, x + h - 3, y + h - 3, CLR32_CURSE_RED); /* draw the object tile */ if (obj) { int tile_x, tile_y; int tile = 0; tile = vultures_object_to_tile(obj->otyp, -1, -1, obj); weight = obj->owt; tile_x = x + h/2; tile_y = y + h * 3 / 4; if (TILE_IS_OBJECT(tile)) { tile = tile - OBJTILEOFFSET + ICOTILEOFFSET; tile_x = x + 2; tile_y = y + 2; } vultures_put_tile(tile_x, tile_y, tile); } /* draw the item letter on the top left corner of the object tile */ snprintf(tmpstr, 11, "%c", accelerator); vultures_put_text_shadow(V_FONT_MENU, tmpstr, vultures_screen, x + 2, y + 2, textcolor, CLR32_BLACK); /* draw the quantity on the tile */ if (obj && obj->quan > 1) { snprintf(tmpstr, 11, "%ld", obj->quan); txt_height = vultures_text_height(V_FONT_MENU, tmpstr); text_start_x = x + h - vultures_text_length(V_FONT_MENU, tmpstr) - 2; vultures_put_text_shadow(V_FONT_MENU, tmpstr, vultures_screen, text_start_x, y + h - txt_height, CLR32_WHITE, CLR32_BLACK); } /* restore the drawing region */ vultures_set_draw_region(0, 0, vultures_screen->w - 1, vultures_screen->h - 1); vultures_invalidate_region(x, y, w, h); return 0; }