Pass font to gr_get_string_size

This commit is contained in:
Kp 2017-01-08 22:31:59 +00:00
parent 0480ba8030
commit 1ef6b9d5bc
25 changed files with 83 additions and 84 deletions

View file

@ -119,7 +119,7 @@ static void print_clock()
array<char, 20> message;
if (!strftime(message.data(), message.size(), "%m-%d %H:%M:%S", &Editor_time_of_day))
message[0] = 0;
gr_get_string_size(message.data(), &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, message.data(), &w, &h, nullptr);
const uint8_t color = CGREY;
gr_rect(*grd_curcanv, 700, 0, 799, h + 1, color);
gr_string(700, 0, message.data());

View file

@ -282,7 +282,7 @@ void gr_printt(int x, int y, const char *format, ...) __attribute_format_printf(
#define gr_printf(A1,A2,F,...) dxx_call_printf_checked(gr_printfs,gr_string,(A1,A2),(F),##__VA_ARGS__)
#define gr_uprintf(A1,A2,F,...) dxx_call_printf_checked(gr_printfus,gr_ustring,(A1,A2),(F),##__VA_ARGS__)
std::pair<const char *, unsigned> gr_get_string_wrap(const char *s, unsigned limit);
void gr_get_string_size(const char *s, int *string_width, int *string_height, int *average_width);
void gr_get_string_size(const grs_font &, const char *s, int *string_width, int *string_height, int *average_width);
// From scale.c
void scale_bitmap(const grs_bitmap &bp, const array<grs_point, 3> &vertbuf, int orientation);

View file

@ -186,7 +186,7 @@ unsigned CLIState::draw(unsigned y, unsigned line_spacing)
const auto margin_width = FSPACX(1);
const char prompt_string[2] = {g_prompt_strings[0], 0};
int prompt_width, h;
gr_get_string_size(prompt_string, &prompt_width, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, prompt_string, &prompt_width, &h, nullptr);
y -= line_spacing;
const auto canvas_width = GWIDTH;
const unsigned max_pixels_per_line = canvas_width - (margin_width * 2) - prompt_width;
@ -225,7 +225,7 @@ unsigned CLIState::draw(unsigned y, unsigned line_spacing)
const auto line_left = margin_width + prompt_width + 1;
const auto cursor_string = (m_insert_type == CLI_insert_type::insert ? CLI_INS_CURSOR : CLI_OVR_CURSOR);
int cursor_width, cursor_height;
gr_get_string_size(cursor_string, &cursor_width, &cursor_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, cursor_string, &cursor_width, &cursor_height, nullptr);
if (line_position == m_line.size())
{
const auto &w = wraps[last_wrap_line % wraps.size()];
@ -299,7 +299,7 @@ unsigned CLIState::draw(unsigned y, unsigned line_spacing)
if (line_position != p - line_begin)
{
int cw;
gr_get_string_size(&line_begin[line_position], &cw, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, &line_begin[line_position], &cw, nullptr, nullptr);
cx -= cw;
}
gr_string(*grd_curcanv, cx, cy, cursor_string, cursor_width, cursor_height);

View file

@ -47,7 +47,7 @@ int ui_button_any_drawn = 0;
void ui_get_button_size( const char * text, int * width, int * height )
{
gr_get_string_size(text, width, height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, text, width, height, nullptr);
*width += BUTTON_EXTRA_WIDTH*2;
*width += 6;
*height += BUTTON_EXTRA_HEIGHT*2;

View file

@ -55,7 +55,7 @@ void ui_draw_icon( UI_GADGET_ICON * icon )
icon->status = 0;
gr_set_current_canvas( icon->canvas );
gr_get_string_size(icon->text.get(), &width, &height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, icon->text.get(), &width, &height, nullptr);
x = ((icon->width-1)/2)-((width-1)/2);
y = ((icon->height-1)/2)-((height-1)/2);

View file

@ -43,7 +43,7 @@ void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox )
gr_rect(*grd_curcanv, 0, 0, inputbox->width-1, inputbox->height-1, CBLACK);
int w, h;
gr_get_string_size(inputbox->text.get(), &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, inputbox->text.get(), &w, &h, nullptr);
if (dlg->keyboard_focus_gadget == inputbox)
{
if (inputbox->first_time)
@ -73,7 +73,7 @@ void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox )
std::unique_ptr<UI_GADGET_INPUTBOX> ui_add_gadget_inputbox(UI_DIALOG * dlg, short x, short y, short length, short slength, const char * text)
{
int h, aw;
gr_get_string_size(nullptr, nullptr, &h, &aw);
gr_get_string_size(*grd_curcanv->cv_font, nullptr, nullptr, &h, &aw);
std::unique_ptr<UI_GADGET_INPUTBOX> inputbox{ui_gadget_add<UI_GADGET_INPUTBOX>(dlg, x, y, x+aw*slength-1, y+h-1+4)};
MALLOC(inputbox->text, char[], length + 1);
auto ltext = strlen(text) + 1;

View file

@ -89,7 +89,7 @@ void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox )
else
gr_set_fontcolor( CBLACK, -1 );
}
gr_get_string_size(listbox->list[i], &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, listbox->list[i], &w, &h, nullptr);
gr_string(*grd_curcanv, x + 2, y, listbox->list[i], w, h);
y += h;
}
@ -118,7 +118,7 @@ static void gr_draw_sunken_border( short x1, short y1, short x2, short y2 )
std::unique_ptr<UI_GADGET_LISTBOX> ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list)
{
int th, i;
gr_get_string_size("*", nullptr, &th, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, "*", nullptr, &th, nullptr);
i = h / th;
h = i * th;

View file

@ -828,7 +828,7 @@ int menubar_init( const char * file )
{
w = 1; h = 3;
} else {
gr_get_string_size(item.Text.get(), &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, item.Text.get(), &w, &h, nullptr);
w += 2;
h += 2;
}

View file

@ -126,7 +126,7 @@ int (ui_messagebox)( short xc, short yc, const char * text, const ui_messagebox_
if ( height > button_height ) button_height = height;
}
gr_get_string_size(text, &text_width, &text_height, &avg );
gr_get_string_size(*grd_curcanv->cv_font, text, &text_width, &text_height, &avg);
width = button_width*Button.count();
width += BUTTON_HORZ_SPACING*(Button.count()+1);

View file

@ -58,7 +58,7 @@ std::unique_ptr<UI_GADGET_SCROLLBAR> ui_add_gadget_scrollbar(UI_DIALOG * dlg, sh
auto &up = "\x1e";
auto &down = "\x1f";
gr_get_string_size(up, &tw, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, up, &tw, nullptr, nullptr);
w = tw + 10;

View file

@ -39,7 +39,7 @@ void ui_string_centered( short x, short y, const char * s )
{
int height, width;
gr_get_string_size(s, &width, &height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &width, &height, nullptr);
//baseline = height-grd_curcanv->cv_font->ft_baseline;

View file

@ -1827,7 +1827,7 @@ void show_escort_menu(const array<char, 300> &amsg)
gr_set_curfont( GAME_FONT );
gr_get_string_size(msg, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, msg, &w, &h, nullptr);
x = (SWIDTH-w)/2;
y = (SHEIGHT-h)/2;

View file

@ -301,7 +301,7 @@ static window_event_result show_pause_message(window *, const d_event &event, co
gr_set_current_canvas(NULL);
gr_set_curfont( GAME_FONT );
gr_get_string_size(msg, nullptr, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, msg, nullptr, &h, nullptr);
y = (grd_curscreen->get_screen_height() - h) / 2;

View file

@ -692,7 +692,7 @@ static int gr_internal_color_string(grs_canvas &canvas, const int x, const int y
void gr_string(const int x, const int y, const char *const s)
{
int w, h;
gr_get_string_size(s, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &w, &h, nullptr);
gr_string(*grd_curcanv, x, y, s, w, h);
}
@ -774,11 +774,10 @@ void gr_ustring(int x, int y, const char *s )
gr_ustring_mono(*grd_curcanv, x, y, s);
}
void gr_get_string_size(const char *s, int *string_width, int *string_height, int *average_width )
void gr_get_string_size(const grs_font &cv_font, const char *s, int *const string_width, int *const string_height, int *const average_width)
{
float longest_width=0.0,string_width_f=0.0;
unsigned lines = 0;
const auto &cv_font = *grd_curcanv->cv_font;
if (average_width)
*average_width = cv_font.ft_w;
if (!string_width && !string_height)

View file

@ -176,7 +176,7 @@ static void print_status_bar( char message[DIAGNOSTIC_MESSAGE_MAX] ) {
gr_set_curfont(editor_font);
gr_set_fontcolor( CBLACK, CGREY );
int w,h;
gr_get_string_size( message, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, message, &w, &h, nullptr);
gr_string(*grd_curcanv, 4, 583, message, w, h);
gr_set_fontcolor( CBLACK, CWHITE );
gr_rect(*grd_curcanv, 4+w, 583, 799, 599, CGREY);

View file

@ -535,7 +535,7 @@ static void name_frame(automap *am)
gr_string((SWIDTH/64),(SHEIGHT/48),name_level_left);
int wr,h;
gr_get_string_size(name_level_right, &wr, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, name_level_right, &wr, &h, nullptr);
gr_string(*grd_curcanv, grd_curcanv->cv_bitmap.bm_w-wr-(SWIDTH/64),(SHEIGHT/48),name_level_right, wr, h);
#endif
}

View file

@ -180,7 +180,7 @@ static void con_draw(void)
auto &b = con_buffer[CON_LINES_MAX - 1 - i];
gr_set_fontcolor(get_console_color_by_priority(b.priority), -1);
int w,h;
gr_get_string_size(b.line, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, b.line, &w, &h, nullptr);
y -= h + fspacy1;
gr_string(*grd_curcanv, fspacx1, y, b.line, w, h);
i++;

View file

@ -908,7 +908,7 @@ void show_boxed_message(const char *msg, int RenderFlag)
gr_set_current_canvas(NULL);
gr_set_curfont( MEDIUM1_FONT );
gr_set_fontcolor(BM_XRGB(31, 31, 31), -1);
gr_get_string_size(msg, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, msg, &w, &h, nullptr);
x = (SWIDTH-w)/2;
y = (SHEIGHT-h)/2;

View file

@ -686,7 +686,7 @@ static void hud_show_score(const player_info &player_info)
gr_set_fontcolor(Color_0_31_0, -1);
int w, h;
gr_get_string_size(score_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, score_str, &w, &h, nullptr);
gr_string(*grd_curcanv, grd_curcanv->cv_bitmap.bm_w - w - FSPACX(1), FSPACY(1), score_str, w, h);
}
@ -714,7 +714,7 @@ static void hud_show_timer_count()
char score_str[20];
snprintf(score_str, sizeof(score_str), "T - %5d", i);
int w, h;
gr_get_string_size(score_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, score_str, &w, &h, nullptr);
gr_string(*grd_curcanv, grd_curcanv->cv_bitmap.bm_w-w-FSPACX(12), LINE_SPACING+FSPACY(1), score_str, w, h);
}
}
@ -748,7 +748,7 @@ static void hud_show_score_added()
gr_set_fontcolor(BM_XRGB(0, color, 0),-1 );
int w, h;
gr_get_string_size(score_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, score_str, &w, &h, nullptr);
gr_string(*grd_curcanv, grd_curcanv->cv_bitmap.bm_w - w - FSPACX(PlayerCfg.CockpitMode[1] == CM_FULL_SCREEN ? 1 : 12), LINE_SPACING + FSPACY(1), score_str, w, h);
} else {
score_time = 0;
@ -772,7 +772,7 @@ static void sb_show_score(const player_info &player_info, const local_multires_g
? player_info.net_kills_total
: (gr_set_fontcolor(BM_XRGB(0,31,0), -1), player_info.mission.score));
int w, h;
gr_get_string_size(score_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, score_str, &w, &h, nullptr);
x = HUD_SCALE_X(SB_SCORE_RIGHT)-w-FSPACX(1);
y = HUD_SCALE_Y(SB_SCORE_Y);
@ -814,7 +814,7 @@ static void sb_show_score_added(const local_multires_gauge_graphic multires_gaug
: (snprintf(score_buf, sizeof(score_buf), "%5d", score_display), score_buf);
int w, h;
gr_get_string_size(score_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, score_str, &w, &h, nullptr);
x = HUD_SCALE_X(SB_SCORE_ADDED_RIGHT)-w-FSPACX(1);
gr_set_fontcolor(BM_XRGB(0, color, 0),-1 );
gr_string(*grd_curcanv, x, HUD_SCALE_Y(SB_SCORE_ADDED_Y), score_str, w, h);
@ -1083,7 +1083,7 @@ static void show_bomb_count(const player_info &player_info, const int x, const i
std::replace(&txt[2], &txt[4], '1', '\x84');
int w, h;
gr_get_string_size(txt, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, txt, &w, &h, nullptr);
gr_string(*grd_curcanv, right_align ? x - w : x, y, txt, w, h);
}
}
@ -1269,7 +1269,7 @@ static void hud_show_primary_weapons_mode(const player_info &player_info, const
continue;
}
int w, h;
gr_get_string_size(txtweapon, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, txtweapon, &w, &h, nullptr);
if (vertical){
y -= h + fspacy2;
}else
@ -1353,7 +1353,7 @@ static void hud_show_primary_weapons_mode(const player_info &player_info, const
continue;
}
int w, h;
gr_get_string_size(txtweapon, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, txtweapon, &w, &h, nullptr);
if (vertical){
y -= h + fspacy2;
}else
@ -1392,7 +1392,7 @@ static void hud_show_secondary_weapons_mode(const player_info &player_info, cons
hud_set_secondary_weapon_fontcolor(player_info, i);
snprintf(weapon_str, sizeof(weapon_str), "%i", secondary_ammo[i]);
int w, h;
gr_get_string_size(weapon_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, weapon_str, &w, &h, nullptr);
if (vertical){
y -= h + fspacy2;
}else
@ -1422,7 +1422,7 @@ static void hud_show_secondary_weapons_mode(const player_info &player_info, cons
hud_set_secondary_weapon_fontcolor(player_info, i);
snprintf(weapon_str, sizeof(weapon_str), "%u", secondary_ammo[i]);
int w, h;
gr_get_string_size(weapon_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, weapon_str, &w, &h, nullptr);
if (vertical){
y -= h + fspacy2;
}else
@ -1467,8 +1467,8 @@ static void hud_show_weapons(const object &plrobj)
{
int x1,x2;
int w;
gr_get_string_size("V1000", &w, nullptr, nullptr);
gr_get_string_size("0 ", &x2, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, "V1000", &w, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, "0 ", &x2, nullptr, nullptr);
y=grd_curcanv->cv_bitmap.bm_h/1.75;
x1 = grd_curcanv->cv_bitmap.bm_w / 2.1 - (fspacx(40) + w);
x2 = grd_curcanv->cv_bitmap.bm_w / 1.9 + (fspacx(42) + x2);
@ -1530,7 +1530,7 @@ static void hud_show_weapons(const object &plrobj)
}
int w, h;
gr_get_string_size(disp_primary_weapon_name, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, disp_primary_weapon_name, &w, &h, nullptr);
const auto &&bmwx = grd_curcanv->cv_bitmap.bm_w - fspacx(1);
gr_string(*grd_curcanv, bmwx - w, y - (line_spacing * 2), disp_primary_weapon_name, w, h);
const char *disp_secondary_weapon_name;
@ -1539,7 +1539,7 @@ static void hud_show_weapons(const object &plrobj)
disp_secondary_weapon_name = SECONDARY_WEAPON_NAMES_VERY_SHORT(Secondary_weapon);
snprintf(weapon_str, sizeof(weapon_str), "%s %u", disp_secondary_weapon_name, player_info.secondary_ammo[Secondary_weapon]);
gr_get_string_size(weapon_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, weapon_str, &w, &h, nullptr);
gr_string(*grd_curcanv, bmwx - w, y - line_spacing, weapon_str, w, h);
show_bomb_count(player_info, bmwx, y - (line_spacing * 3), -1, 1, 1);
@ -1652,7 +1652,7 @@ static void sb_show_lives(const player_info &player_info, const local_multires_g
snprintf(killed_str, sizeof(killed_str), "%5d", player_info.net_killed_total);
int w, h;
gr_get_string_size(killed_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, killed_str, &w, &h, nullptr);
const auto x = HUD_SCALE_X(SB_SCORE_RIGHT)-w-FSPACX(1);
gr_rect(*grd_curcanv, exchange(last_x[multires_gauge_graphic.is_hires()], x), HUD_SCALE_Y(y), HUD_SCALE_X(SB_SCORE_RIGHT), HUD_SCALE_Y(y)+LINE_SPACING, color);
gr_string(*grd_curcanv, x, HUD_SCALE_Y(y), killed_str, w, h);
@ -2076,7 +2076,7 @@ static void show_cockpit_cloak_invul_timer(const fix64 effect_end, int y)
int ow, oh;
snprintf(countdown, sizeof(countdown), "%lu", static_cast<unsigned long>(effect_end / F1_0));
gr_set_fontcolor(BM_XRGB(31, 31, 31), -1);
gr_get_string_size(countdown, &ow, &oh, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, countdown, &ow, &oh, nullptr);
const int x = grd_curscreen->get_screen_width() / (PlayerCfg.CockpitMode[1] == CM_STATUS_BAR
? 2.266
: 1.951
@ -2173,7 +2173,7 @@ static void draw_numerical_display(int shield, int energy, const local_multires_
// gr_get_string_size is used so we can get the numbers finally in the correct position with sw and ew
const auto a = [](int xb, int v, int y) {
int w;
gr_get_string_size(get_gauge_width_string(v), &w, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, get_gauge_width_string(v), &w, nullptr, nullptr);
gr_printf(xb - (w / 2), y, "%d", v);
};
gr_set_fontcolor(BM_XRGB(14,14,23),-1 );
@ -2552,7 +2552,7 @@ static void sb_draw_energy_bar(int energy, const local_multires_gauge_graphic mu
//draw numbers
gr_set_fontcolor(BM_XRGB(25,18,6),-1 );
gr_get_string_size(get_gauge_width_string(energy), &ew, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, get_gauge_width_string(energy), &ew, nullptr, nullptr);
#if defined(DXX_BUILD_DESCENT_I)
unsigned y = SB_ENERGY_NUM_Y;
#elif defined(DXX_BUILD_DESCENT_II)
@ -2590,7 +2590,7 @@ static void sb_draw_afterburner(const player_info &player_info, const local_mult
gr_set_fontcolor(gr_find_closest_color(r,g,b), -1);
int w, h;
gr_get_string_size(ab_str, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, ab_str, &w, &h, nullptr);
gr_string(*grd_curcanv, HUD_SCALE_X(SB_AFTERBURNER_GAUGE_X + (SB_AFTERBURNER_GAUGE_W + 1) / 2) - (w / 2), HUD_SCALE_Y(SB_AFTERBURNER_GAUGE_Y + (SB_AFTERBURNER_GAUGE_H - GAME_FONT->ft_h - (GAME_FONT->ft_h / 4))), "AB", w, h);
gr_set_current_canvas(NULL);
}
@ -2604,7 +2604,7 @@ static void sb_draw_shield_num(int shield, const local_multires_gauge_graphic mu
gr_set_curfont( GAME_FONT );
gr_set_fontcolor(BM_XRGB(14,14,23),-1 );
gr_get_string_size(get_gauge_width_string(shield), &sw, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, get_gauge_width_string(shield), &sw, nullptr, nullptr);
gr_printf((grd_curscreen->get_screen_width() / 2.266) - (sw / 2), HUD_SCALE_Y(SB_SHIELD_NUM_Y), "%d", shield);
}
@ -3001,14 +3001,14 @@ static void hud_show_kill_list()
else
name = Players[player_num].callsign; // Note link to above if!!
int sw, sh;
gr_get_string_size(static_cast<const char *>(name), &sw, &sh, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, static_cast<const char *>(name), &sw, &sh, nullptr);
{
const auto b = x1 - x0 - fspacx2;
if (sw > b)
for (char *e = &name.buffer()[strlen(name)];;)
{
*--e = 0;
gr_get_string_size(name, &sw, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, name, &sw, nullptr, nullptr);
if (!(sw > b))
break;
}
@ -3146,7 +3146,7 @@ void show_HUD_names()
if (written)
{
int w, h;
gr_get_string_size(s, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &w, &h, nullptr);
const auto color = get_player_or_team_color(pnum);
gr_set_fontcolor(BM_XRGB(player_rgb[color].r, player_rgb[color].g, player_rgb[color].b), -1);
x1 = f2i(x)-w/2;

View file

@ -248,7 +248,7 @@ void player_dead_message(void)
if ( get_local_player().lives < 2 ) {
int x, y, w, h;
gr_set_curfont( HUGE_FONT );
gr_get_string_size(TXT_GAME_OVER, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, TXT_GAME_OVER, &w, &h, nullptr);
const int gw = w;
const int gh = h;
w += 20;

View file

@ -862,14 +862,14 @@ static int get_item_height(const kc_item &item, const kc_mitem &mitem)
btext = get_item_text(item, mitem, buf);
if (!btext)
return 0;
gr_get_string_size(btext, nullptr, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, btext, nullptr, &h, nullptr);
return h;
}
static void kc_gr_2y_string(const char *const s, const font_y_scaled_float y, const font_x_scaled_float x0, const font_x_scaled_float x1)
{
int w, h;
gr_get_string_size(s, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &w, &h, nullptr);
gr_string(*grd_curcanv, x0, y, s, w, h);
gr_string(*grd_curcanv, x1, y, s, w, h);
}
@ -1377,7 +1377,7 @@ static void kc_drawinput(const kc_item &item, kc_mitem& mitem, int is_current, c
r = 16 * 2, g = 0, b = 19 * 2;
int x, w, h;
gr_get_string_size(btext, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, btext, &w, &h, nullptr);
const uint8_t color = gr_find_closest_color(r, g, b);
const auto &&fspacx_item_xinput = fspacx(item.xinput);
const auto &&fspacy_item_y = fspacy(item.y);
@ -1406,7 +1406,7 @@ static void kc_drawquestion( kc_menu *menu, const kc_item *item )
if (menu->q_fade_i>63) menu->q_fade_i=0;
int w, h;
gr_get_string_size("?", &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, "?", &w, &h, nullptr);
const auto &&fspacx = FSPACX();
const auto &&fspacy = FSPACY();

View file

@ -1143,7 +1143,7 @@ static int net_udp_list_join_poll( newmenu *menu,const d_event &event, direct_jo
continue;
thold[0]=Active_udp_games[(i+(NLPage*UDP_NETGAMES_PPAGE))].mission_title[j];
int tx;
gr_get_string_size (thold, &tx, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, thold, &tx, nullptr, nullptr);
if ((x += tx) >= fspacx(55))
{
@ -1162,7 +1162,7 @@ static int net_udp_list_join_poll( newmenu *menu,const d_event &event, direct_jo
continue;
thold[0]=Active_udp_games[(i+(NLPage*UDP_NETGAMES_PPAGE))].game_name[j];
int tx;
gr_get_string_size (thold, &tx, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, thold, &tx, nullptr, nullptr);
if ((x += tx) >= fspacx(55))
{

View file

@ -252,7 +252,7 @@ static void nm_string( int w1,int x, int y, const char * s, int tabs_flag)
}
measure[0]=s2[i];
int tx, th;
gr_get_string_size(measure, &tx, &th, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, measure, &tx, &th, nullptr);
gr_string(*grd_curcanv, x, y, measure, tx, th);
x+=tx;
}
@ -262,7 +262,7 @@ static void nm_string( int w1,int x, int y, const char * s, int tabs_flag)
if (!tabs_flag && p && (w1>0) ) {
int w, h;
gr_get_string_size(s1, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s1, &w, &h, nullptr);
gr_string(*grd_curcanv, x + w1 - w, y, s1, w, h);
@ -287,7 +287,7 @@ static void nm_string_slider( int w1,int x, int y, char * s )
if (p) {
int w, h;
gr_get_string_size(s1, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s1, &w, &h, nullptr);
gr_string(*grd_curcanv, x + w1 - w, y, s1, w, h);
*p = '\t';
@ -299,7 +299,7 @@ static void nm_string_slider( int w1,int x, int y, char * s )
static void nm_string_black( int w1,int x, int y, const char * s )
{
int w,h;
gr_get_string_size(s, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &w, &h, nullptr);
if (w1 == 0) w1 = w;
@ -326,7 +326,7 @@ static void nm_string_black( int w1,int x, int y, const char * s )
static void nm_rstring( int w1,int x, int y, const char * s )
{
int w, h;
gr_get_string_size(s, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s, &w, &h, nullptr);
x -= FSPACX(3);
if (w1 == 0) w1 = w;
@ -341,7 +341,7 @@ static void nm_string_inputbox( int w, int x, int y, const char * text, int curr
if (strlen(text)>75)
text+=strlen(text)-75;
while( *text ) {
gr_get_string_size(text, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, text, &w1, nullptr, nullptr);
if ( w1 > w-FSPACX(10) )
text++;
else
@ -779,7 +779,7 @@ static window_event_result newmenu_mouse(window *wind,const d_event &event, newm
if (menu->scroll_offset != 0) {
int arrow_width, arrow_height;
gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, UP_ARROW_MARKER, &arrow_width, &arrow_height, nullptr);
x1 = grd_curcanv->cv_bitmap.bm_x + BORDERX - fspacx(12);
y1 = grd_curcanv->cv_bitmap.bm_y + menu->items[menu->scroll_offset].y-((static_cast<int>(LINE_SPACING))*menu->scroll_offset);
x2 = x1 + arrow_width;
@ -790,7 +790,7 @@ static window_event_result newmenu_mouse(window *wind,const d_event &event, newm
}
if (menu->scroll_offset+menu->max_displayable<menu->nitems) {
int arrow_width, arrow_height;
gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, DOWN_ARROW_MARKER, &arrow_width, &arrow_height, nullptr);
x1 = grd_curcanv->cv_bitmap.bm_x + BORDERX - fspacx(12);
y1 = grd_curcanv->cv_bitmap.bm_y + menu->items[menu->scroll_offset+menu->max_displayable-1].y-((static_cast<int>(LINE_SPACING))*menu->scroll_offset);
x2 = x1 + arrow_width;
@ -827,10 +827,10 @@ static window_event_result newmenu_mouse(window *wind,const d_event &event, newm
}
if (p) {
int slider_width, sleft_width, sright_width, smiddle_width;
gr_get_string_size(s1, &slider_width, nullptr, nullptr);
gr_get_string_size(SLIDER_LEFT, &sleft_width, nullptr, nullptr);
gr_get_string_size(SLIDER_RIGHT, &sright_width, nullptr, nullptr);
gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, s1, &slider_width, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, SLIDER_LEFT, &sleft_width, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, SLIDER_RIGHT, &sright_width, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, SLIDER_MIDDLE, &smiddle_width, nullptr, nullptr);
x1 = grd_curcanv->cv_bitmap.bm_x + citem.x + citem.w - slider_width;
x2 = x1 + slider_width + sright_width;
@ -1215,14 +1215,14 @@ static void newmenu_create_structure( newmenu *menu )
if ( menu->title ) {
gr_set_curfont(HUGE_FONT);
int string_width, string_height;
gr_get_string_size(menu->title, &string_width, &string_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, menu->title, &string_width, &string_height, nullptr);
tw = string_width;
th = string_height;
}
if ( menu->subtitle ) {
gr_set_curfont(MEDIUM3_FONT);
int string_width, string_height;
gr_get_string_size(menu->subtitle, &string_width, &string_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, menu->subtitle, &string_width, &string_height, nullptr);
if (string_width > tw )
tw = string_width;
th += string_height;
@ -1243,7 +1243,7 @@ static void newmenu_create_structure( newmenu *menu )
{
i.y = menu->h;
int string_width, string_height, average_width;
gr_get_string_size(i.text,&string_width,&string_height,&average_width);
gr_get_string_size(*grd_curcanv->cv_font, i.text, &string_width, &string_height, &average_width);
i.right_offset = 0;
i.saved_text[0] = '\0';
@ -1259,7 +1259,7 @@ static void newmenu_create_structure( newmenu *menu )
index += snprintf(i.saved_text.data() + index, i.saved_text.size() - index, "%s", SLIDER_MIDDLE);
}
index += snprintf(i.saved_text.data() + index, i.saved_text.size() - index, "%s", SLIDER_RIGHT);
gr_get_string_size(i.saved_text.data(), &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, i.saved_text.data(), &w1, nullptr, nullptr);
string_width += w1 + aw;
}
@ -1272,9 +1272,9 @@ static void newmenu_create_structure( newmenu *menu )
{
int w1;
nothers++;
gr_get_string_size(NORMAL_CHECK_BOX, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, NORMAL_CHECK_BOX, &w1, nullptr, nullptr);
i.right_offset = w1;
gr_get_string_size(CHECKED_CHECK_BOX, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, CHECKED_CHECK_BOX, &w1, nullptr, nullptr);
if (w1 > i.right_offset)
i.right_offset = w1;
}
@ -1283,9 +1283,9 @@ static void newmenu_create_structure( newmenu *menu )
{
int w1;
nothers++;
gr_get_string_size(NORMAL_RADIO_BOX, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, NORMAL_RADIO_BOX, &w1, nullptr, nullptr);
i.right_offset = w1;
gr_get_string_size(CHECKED_RADIO_BOX, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, CHECKED_RADIO_BOX, &w1, nullptr, nullptr);
if (w1 > i.right_offset)
i.right_offset = w1;
}
@ -1297,10 +1297,10 @@ static void newmenu_create_structure( newmenu *menu )
nothers++;
auto &number = i.number();
snprintf(test_text, sizeof(test_text), "%d", number.max_value);
gr_get_string_size(test_text, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, test_text, &w1, nullptr, nullptr);
i.right_offset = w1;
snprintf(test_text, sizeof(test_text), "%d", number.min_value);
gr_get_string_size(test_text, &w1, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, test_text, &w1, nullptr, nullptr);
if (w1 > i.right_offset)
i.right_offset = w1;
}
@ -1464,7 +1464,7 @@ static window_event_result newmenu_draw(window *wind, newmenu *menu)
gr_set_curfont(HUGE_FONT);
gr_set_fontcolor( BM_XRGB(31,31,31), -1 );
int string_width, string_height;
gr_get_string_size(menu->title, &string_width, &string_height, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, menu->title, &string_width, &string_height, nullptr);
th = string_height;
gr_string(*grd_curcanv, 0x8000, ty, menu->title, string_width, string_height);
}
@ -1751,7 +1751,7 @@ static window_event_result listbox_mouse(window *, const d_event &event, listbox
if (i >= lb->nitems)
break;
int h;
gr_get_string_size(lb->item[i], nullptr, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, lb->item[i], nullptr, &h, nullptr);
x1 = lb->box_x;
x2 = lb->box_x + lb->box_w;
y1 = (i - lb->first_item) * line_spacing + lb->box_y;
@ -1770,7 +1770,7 @@ static window_event_result listbox_mouse(window *, const d_event &event, listbox
return window_event_result::ignored;
mouse_get_pos(&mx, &my, &mz);
gr_get_string_size(lb->item[lb->citem], nullptr, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, lb->item[lb->citem], nullptr, &h, nullptr);
x1 = lb->box_x;
x2 = lb->box_x + lb->box_w;
y1 = (lb->citem-lb->first_item)*LINE_SPACING+lb->box_y;
@ -1902,7 +1902,7 @@ static void listbox_create_structure( listbox *lb)
range_for (auto &i, unchecked_partial_range(lb->item, lb->nitems))
{
int w;
gr_get_string_size(i, &w, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, i, &w, nullptr, nullptr);
if ( w > lb->box_w )
lb->box_w = w + fspacx(10);
}
@ -1910,7 +1910,7 @@ static void listbox_create_structure( listbox *lb)
{
int w, h;
gr_get_string_size(lb->title, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, lb->title, &w, &h, nullptr);
if ( w > lb->box_w )
lb->box_w = w;
lb->title_height = h+FSPACY(5);
@ -1923,7 +1923,7 @@ static void listbox_create_structure( listbox *lb)
int w;
lb->box_w = SWIDTH - (BORDERX*2);
gr_get_string_size("O", &w, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, "O", &w, nullptr, nullptr);
lb->marquee_maxchars = lb->box_w/w;
lb->marquee_lasttime = timer_query();
}

View file

@ -276,7 +276,7 @@ static void scores_rputs(int x, int y, char *buffer)
if (*p=='1') *p=132;
int w, h;
gr_get_string_size(buffer, &w, &h, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, buffer, &w, &h, nullptr);
gr_string(*grd_curcanv, FSPACX(x) - w, FSPACY(y), buffer, w, h);
}

View file

@ -694,7 +694,7 @@ static void put_char_delay(briefing *br, char ch)
br->streamcount++;
br->prev_ch = ch;
gr_get_string_size(str, &w, nullptr, nullptr);
gr_get_string_size(*grd_curcanv->cv_font, str, &w, nullptr, nullptr);
br->text_x += w;
#if defined(DXX_BUILD_DESCENT_II)