MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / Print

Method Print

PanzerChasm/text_drawer_soft.cpp:58–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void TextDrawerSoft::Print(
59 const int x, const int y,
60 const char* const text,
61 const unsigned int scale,
62 const FontColor color,
63 const Alignment alignment )
64{
65 const PaletteTransformed& palette= *rendering_context_.palette_transformed;
66 uint32_t* const dst_pixels= rendering_context_.window_surface_data;
67 const int dst_row_pixels= rendering_context_.row_pixels;
68 const int max_x= int( rendering_context_.viewport_size.Width () );
69 const int max_y= int( rendering_context_.viewport_size.Height() );
70
71 const int scale_i= int(scale);
72 const int d_tc_v= int(color) * int(FontParams::atlas_height);
73
74 int current_y= y;
75
76 const char* c= text;
77 while( 1 )
78 {
79 if( *c == '\0' )
80 break;
81
82 unsigned int line_width= 0u;
83 const char* line_end_c= c;
84 while( ! ( *line_end_c == '\n' || *line_end_c == '\0' ) )
85 {
86 line_width+= letters_width_[ int(*line_end_c) ];
87 line_end_c++;
88 }
89
90 int current_x;
91 if( alignment == Alignment::Center )
92 current_x= x - int( scale_i * line_width / 2u );
93 else if( alignment == Alignment::Right )
94 current_x= x - int( scale_i * line_width );
95 else
96 current_x= x;
97
98 while( !( *c == '\n' || *c == '\0' ) )
99 {
100 // Convert to unsigned - allow chars with codes 128 - 255.
101 const unsigned int code= static_cast<unsigned char>(*c);
102
103 const int letter_width= int( letters_width_[ code ] );
104
105 const int glyph_tc_u= FontParams::letter_place_width * ( int(code) & 15 ) + FontParams::letter_u_offset;
106 const int glyph_tc_v= FontParams::letter_place_height * ( int(code) >> 4 ) + FontParams::letter_v_offset + d_tc_v;
107
108 for( int glyph_y= 0; glyph_y < FontParams::letter_place_height - FontParams::letter_v_offset; glyph_y++ )
109 for( int glyph_x= 0; glyph_x < letter_width; glyph_x++ )
110 {
111 const unsigned char color_index=
112 font_texture_data_[
113 ( glyph_tc_u + glyph_x ) +
114 ( glyph_tc_v + glyph_y ) * int(FontParams::atlas_width) ];
115 if( color_index == 255u )

Callers

nothing calls this directly

Calls 2

WidthMethod · 0.80
HeightMethod · 0.80

Tested by

no test coverage detected