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

Method Draw

PanzerChasm/console.cpp:138–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138void Console::Draw()
139{
140 const Time current_time= Time::CurrentTime();
141 const float time_delta_s= ( current_time - last_draw_time_ ).ToSeconds();
142 last_draw_time_= current_time;
143
144 position_+= current_speed_ * time_delta_s;
145 position_= std::min( 1.0f, std::max( 0.0f, position_ ) );
146
147 RemoveOldUserMessages( current_time );
148 if( position_ <= 0.0f )
149 {
150 DrawUserMessages();
151 return;
152 }
153
154 shared_drawers_->menu->DrawConsoleBackground( position_ );
155
156 const int letter_height= int( shared_drawers_->text->GetLineHeight() );
157 const int scale= int( shared_drawers_->menu->GetConsoleScale() );
158
159 const unsigned int c_x_offset= 5u;
160 int y= static_cast<int>(
161 position_ * float( shared_drawers_->menu->GetViewportSize().Height() / 2u ) -
162 float( letter_height * scale ) ) - 4 * scale;
163
164 const bool draw_cursor= ( int( current_time.ToSeconds() * 3.0f ) & 1u ) != 0u;
165
166 char line_with_cursor[ c_max_input_line_length + 3u ];
167 std::snprintf( line_with_cursor, sizeof(line_with_cursor), draw_cursor ? ">%s_" : ">%s", input_line_ );
168
169 shared_drawers_->text->Print(
170 scale * c_x_offset, y,
171 line_with_cursor, scale,
172 ITextDrawer::FontColor::Golden, ITextDrawer::Alignment::Left );
173 y-= ( letter_height + 2 ) * scale;
174
175 if( lines_position_ > 0u )
176 {
177 const char* const str=
178 " ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ";
179
180 shared_drawers_->text->Print(
181 scale * c_x_offset, y,
182 str, scale,
183 ITextDrawer::FontColor::White, ITextDrawer::Alignment::Left );
184 y-= letter_height * scale;
185 }
186
187 auto it= lines_.rbegin();
188 it= std::next( it, std::min( lines_position_, static_cast<unsigned int>(lines_.size()) ) );
189 for( ; it != lines_.rend(); ++it )
190 {
191 if( y < -letter_height * scale )
192 break;
193
194 shared_drawers_->text->Print(
195 scale * c_x_offset, y,

Callers

nothing calls this directly

Calls 7

ToSecondsMethod · 0.80
HeightMethod · 0.80
DrawConsoleBackgroundMethod · 0.45
GetLineHeightMethod · 0.45
GetConsoleScaleMethod · 0.45
GetViewportSizeMethod · 0.45
PrintMethod · 0.45

Tested by

no test coverage detected