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; }
/* 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 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; }