void MenuWindow::Draw() { if (_initialized == false) { IF_PRINT_WARNING(VIDEO_DEBUG) << "the menu window was not initialized:\n" << _initialization_errors << endl; return; } if (_window_state == VIDEO_MENU_STATE_HIDDEN) return; VideoManager->PushState(); VideoManager->SetDrawFlags(_xalign, _yalign, VIDEO_BLEND, 0); if (_is_scissored) { ScreenRect rect = _scissor_rect; if (VideoManager->IsScissoringEnabled()) { rect.Intersect(VideoManager->GetScissorRect()); } else { VideoManager->EnableScissoring(); } VideoManager->SetScissorRect(rect); } VideoManager->Move(_x_position, _y_position); _menu_image.Draw(Color::white); if (GUIManager->DEBUG_DrawOutlines() == true) { _DEBUG_DrawOutline(); } VideoManager->PopState(); return; } // void MenuWindow::Draw()
void TextBox::_DrawTextLines(float text_x, float text_y, ScreenRect scissor_rect) { int32 num_chars_drawn = 0; // Calculate the fraction of the text to display float percent_complete; if(_finished) percent_complete = 1.0f; else percent_complete = static_cast<float>(_current_time) / static_cast<float>(_end_time); // Iterate through the loop for every line of text and draw it for(int32 line = 0; line < static_cast<int32>(_text.size()); ++line) { // (1): Calculate the x draw offset for this line and move to that position float line_width = static_cast<float>(TextManager->CalculateTextWidth(_text_style.font, _text[line])); int32 x_align = VideoManager->_ConvertXAlign(_text_xalign); float x_offset = text_x + ((x_align + 1) * line_width) * 0.5f * VideoManager->_current_context.coordinate_system.GetHorizontalDirection(); VideoManager->MoveRelative(x_offset, 0.0f); int32 line_size = static_cast<int32>(_text[line].size()); // (2): Draw the text depending on the display mode and whether or not the gradual display is finished if(_finished || _mode == VIDEO_TEXT_INSTANT) { TextManager->Draw(_text[line], _text_style); } else if(_mode == VIDEO_TEXT_CHAR) { // Determine which character is currently being rendered int32 cur_char = static_cast<int32>(percent_complete * _num_chars); // If the current character to draw is after this line, render the entire line if(num_chars_drawn + line_size < cur_char) { TextManager->Draw(_text[line], _text_style); } // The current character to draw is on this line: figure out which characters on this line should be drawn else { int32 num_completed_chars = cur_char - num_chars_drawn; if(num_completed_chars > 0) { ustring substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring); } } } // else if (_mode == VIDEO_TEXT_CHAR) else if(_mode == VIDEO_TEXT_FADECHAR) { // Figure out which character is currently being rendered float fade_cur_char = percent_complete * _num_chars; int32 cur_char = static_cast<int32>(fade_cur_char); float cur_percent = fade_cur_char - cur_char; // If the current character to draw is after this line, draw the whole line if(num_chars_drawn + line_size <= cur_char) { TextManager->Draw(_text[line], _text_style); } // The current character is on this line: draw any previous characters on this line as well as the current character else { int32 num_completed_chars = cur_char - num_chars_drawn; // Continue only if this line has at least one character that should be drawn if(num_completed_chars >= 0) { ustring substring; // Draw any fully completed characters at full opacity if(num_completed_chars > 0) { substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring, _text_style); } // Draw the current character that is being faded in at the appropriate alpha level Color old_color = _text_style.color; _text_style.color[3] *= cur_percent; VideoManager->MoveRelative(static_cast<float>(TextManager->CalculateTextWidth(_text_style.font, substring)), 0.0f); TextManager->Draw(_text[line].substr(num_completed_chars, 1), _text_style); _text_style.color = old_color; } } } // else if (_mode == VIDEO_TEXT_FADECHAR) else if(_mode == VIDEO_TEXT_FADELINE) { // Deteremine which line is currently being rendered float fade_lines = percent_complete * _text.size(); int32 lines = static_cast<int32>(fade_lines); float cur_percent = fade_lines - lines; // If this line comes before the line being rendered, simply draw the line and be done with it if(line < lines) { TextManager->Draw(_text[line], _text_style); } // Otherwise if this is the line being rendered, determine the amount of alpha for the line being faded in and draw it else if(line == lines) { Color old_color = _text_style.color; _text_style.color[3] *= cur_percent; TextManager->Draw(_text[line], _text_style); _text_style.color = old_color; } } // else if (_mode == VIDEO_TEXT_FADELINE) else if(_mode == VIDEO_TEXT_REVEAL) { // Determine which character is currently being rendered float fade_cur_char = percent_complete * _num_chars; int32 cur_char = static_cast<int32>(fade_cur_char); float cur_percent = fade_cur_char - cur_char; int32 num_completed_chars = cur_char - num_chars_drawn; // If the current character comes after this line, simply render the entire line if(num_chars_drawn + line_size <= cur_char) { TextManager->Draw(_text[line], _text_style); } // If the line contains the current character, draw all previous characters as well as the current one else if(num_completed_chars >= 0) { ustring substring; // If there are already completed characters on this line, draw them in full if(num_completed_chars > 0) { substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring, _text_style); } // Now draw the current character from the line, partially scissored according to the amount that is complete ustring cur_char_string = _text[line].substr(num_completed_chars, 1); // Create a rectangle for the current character, in window coordinates int32 char_x, char_y, char_w, char_h; char_x = static_cast<int32>(x_offset + VideoManager->_current_context.coordinate_system.GetHorizontalDirection() * TextManager->CalculateTextWidth(_text_style.font, substring)); char_y = static_cast<int32>(text_y - VideoManager->_current_context.coordinate_system.GetVerticalDirection() * (_font_properties->height + _font_properties->descent)); if(VideoManager->_current_context.coordinate_system.GetHorizontalDirection() < 0.0f) char_y = static_cast<int32>(VideoManager->_current_context.coordinate_system.GetBottom()) - char_y; if(VideoManager->_current_context.coordinate_system.GetVerticalDirection() < 0.0f) char_x = static_cast<int32>(VideoManager->_current_context.coordinate_system.GetLeft()) - char_x; char_w = TextManager->CalculateTextWidth(_text_style.font, cur_char_string); char_h = _font_properties->height; // Multiply the width by percentage done to determine the scissoring dimensions char_w = static_cast<int32>(cur_percent * char_w); VideoManager->MoveRelative(VideoManager->_current_context.coordinate_system.GetHorizontalDirection() * TextManager->CalculateTextWidth(_text_style.font, substring), 0.0f); // Construct the scissor rectangle using the character dimensions and draw the revealing character VideoManager->PushState(); ScreenRect char_scissor_rect(char_x, char_y, char_w, char_h); scissor_rect.Intersect(char_scissor_rect); VideoManager->EnableScissoring(); VideoManager->SetScissorRect(scissor_rect); TextManager->Draw(cur_char_string, _text_style); VideoManager->PopState(); } // In the else case, the current character is before the line, so we don't draw anything for this line at all } // else if (_mode == VIDEO_TEXT_REVEAL) else { // Invalid display mode: just render the text instantly TextManager->Draw(_text[line]); IF_PRINT_WARNING(VIDEO_DEBUG) << "an unknown/unsupported text display mode was active: " << _mode << std::endl; } // (3): Prepare to draw the next line and move the draw cursor appropriately num_chars_drawn += line_size; // VideoManager->MoveRelative(-xOffset, _font_properties.line_skip * -cs._vertical_direction); text_y += _font_properties->line_skip * -VideoManager->_current_context.coordinate_system.GetVerticalDirection(); VideoManager->Move(0.0f, text_y); } // for (int32 line = 0; line < static_cast<int32>(_text.size()); ++line) } // void TextBox::_DrawLines(float text_x, float text_y, ScreenRect scissor_rect)