Skip to content

Commit

Permalink
Fix city label & note position
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Jul 24, 2021
1 parent c8f5c49 commit 31816b9
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,23 @@ std::string cata_tiles::get_omt_id_rotation_and_subtile(
return ot_type_id.id().str();
}

static void draw_string( Font &font,
const SDL_Renderer_Ptr &renderer,
const GeometryRenderer_Ptr &geometry,
const std::string &str,
point p,
const unsigned char color )
{
const char *cstr = str.c_str();
int len = str.length();
while( len > 0 ) {
const uint32_t ch32 = UTF8_getch( &cstr, &len );
const std::string ch = utf32_to_utf8( ch32 );
font.OutputChar( renderer, geometry, ch, p, color );
p.x += mk_wcwidth( ch32 ) * font.width;
}
}

void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_omt, bool blink )
{
if( !g ) {
Expand Down Expand Up @@ -1035,22 +1052,22 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
const auto abs_sm_to_draw_label = [&]( const tripoint_abs_sm & city_pos, const int label_length ) {
const tripoint tile_draw_pos = global_omt_to_draw_position( project_to<coords::omt>
( city_pos ) ) - o;
point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row );
draw_point.x -= label_length * font->width;
draw_point.x += width / max_col;
point draw_point( tile_draw_pos.x * tile_width + dest.x,
tile_draw_pos.y * tile_height + dest.y );
draw_point.x += ( tile_width - label_length * fontwidth ) / 2;
draw_point.y += ( tile_height - fontheight ) / 2;
return draw_point;
};

// draws a black rectangle behind a label for visibility and legibility
const auto label_bg = [&]( const tripoint_abs_sm & pos, const std::string & name ) {
const int name_length = name.length();
const int name_length = utf8_width( name );
const point draw_pos = abs_sm_to_draw_label( pos, name_length );
SDL_Rect clipRect = { draw_pos.x, draw_pos.y, name_length * fontwidth, fontheight };

geometry->rect( renderer, clipRect, SDL_Color() );

const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) );
map_font->OutputChar( renderer, geometry, name, label_pos, 11 );
draw_string( *font, renderer, geometry, name, draw_pos, 11 );
};

// the tiles on the overmap are overmap tiles, so we need to use
Expand Down Expand Up @@ -1106,26 +1123,27 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
constexpr int padding = 2;

const auto note_bg = [&]( const point & draw_pos, const std::string & name, nc_color & color ) {
const int name_length = name.length();
const int name_length = utf8_width( name );
SDL_Rect clipRect = { draw_pos.x - padding, draw_pos.y - padding, name_length *fontwidth + padding * 2, fontheight + padding * 2};

geometry->rect( renderer, clipRect, SDL_Color{0, 0, 0, 175} );

const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) );
char note_fg_color = color == c_yellow ? 11 :
cata_cursesport::colorpairs[color.to_color_pair_index()].FG;
map_font->OutputChar( renderer, geometry, name, label_pos, note_fg_color );
draw_string( *font, renderer, geometry, name, draw_pos, note_fg_color );
};

auto center_sm = coords::project_to<coords::sm>( tripoint_abs_omt( center_abs_omt.x() + 1,
center_abs_omt.y(), center_abs_omt.z() ) );
const tripoint tile_draw_pos = global_omt_to_draw_position( project_to<coords::omt>
( center_sm ) ) - o;
point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row );
draw_point.x += width / max_col;
point draw_point( tile_draw_pos.x * tile_width + dest.x,
tile_draw_pos.y * tile_height + dest.y );
draw_point.x += padding;
draw_point.y += padding;

nc_color header_color = c_white;
note_bg( draw_point, "Notes:", header_color );
note_bg( draw_point, _( "Notes:" ), header_color );
draw_point.y += fontheight + padding * 2;
for( auto &line : notes_window_text ) {
note_bg( draw_point, line.second, line.first );
Expand Down Expand Up @@ -2362,6 +2380,7 @@ void draw_quick_shortcuts()
text_x = ( ( i + 0.5f ) * width - ( font->width * utf8_width( text ) ) * text_scale * 0.5f ) /
text_scale;
}
// TODO use draw_string instead
text_y = ( WindowHeight - ( height + font->height * text_scale ) * 0.5f ) / text_scale;
font->OutputChar( renderer, geometry, text, point( text_x + 1, text_y + 1 ), 0,
get_option<int>( "ANDROID_SHORTCUT_OPACITY_SHADOW" ) * 0.01f );
Expand Down

0 comments on commit 31816b9

Please sign in to comment.