MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawWidget

Method DrawWidget

src/textfile_gui.cpp:549–590  ·  view source on GitHub ↗

virtual */

Source from the content-addressed store, hash-verified

547}
548
549/* virtual */ void TextfileWindow::DrawWidget(const Rect &r, WidgetID widget) const
550{
551 if (widget == WID_TF_CAPTION && std::size(this->lines) > 0 && this->reflow_iter != this->reflow_end) {
552 /* Draw a progress bar in the caption. */
553 Rect fr = r.Shrink(WidgetDimensions::scaled.captiontext).WithHeight(WidgetDimensions::scaled.vsep_normal, true);
554 size_t remaining = std::distance(this->reflow_iter, this->reflow_end);
555 fr = fr.WithWidth(static_cast<int>(remaining * fr.Width() / std::size(this->lines)), _current_text_dir != TD_RTL);
556 GfxFillRect(fr, PC_WHITE, FILLRECT_CHECKER);
557 }
558
559 if (widget != WID_TF_BACKGROUND) return;
560
561 Rect fr = r.Shrink(WidgetDimensions::scaled.frametext);
562
563 DrawPixelInfo new_dpi;
564 if (!FillDrawPixelInfo(&new_dpi, fr)) return;
565 AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi);
566
567 /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */
568 fr = fr.Translate(-fr.left, -fr.top);
569 int line_height = GetCharacterHeight(FS_MONO);
570
571 if (!this->IsTextWrapped()) fr = ScrollRect(fr, *this->hscroll, this->resize.step_width);
572
573 int pos = this->vscroll->GetPosition();
574 int cap = this->vscroll->GetCapacity();
575 int cur_line = 0;
576 for (auto &line : this->lines) {
577 int top = cur_line;
578 cur_line += line.num_lines;
579 if (cur_line <= pos) continue;
580 if (top > pos + cap) break;
581
582 int y_offset = (top - pos) * line_height;
583 if (line.wrapped_width != 0) {
584 Rect tr = fr.WithWidth(line.wrapped_width, _current_text_dir == TD_RTL);
585 DrawStringMultiLineWithClipping(tr.left, tr.right, y_offset, y_offset + line.num_lines * line_height, line.text, line.colour, SA_TOP | SA_LEFT, false, FS_MONO);
586 } else {
587 DrawString(fr.left, fr.right, y_offset, line.text, line.colour, SA_TOP | SA_LEFT, false, FS_MONO);
588 }
589 }
590}
591
592/* virtual */ void TextfileWindow::OnResize()
593{

Callers

nothing calls this directly

Calls 15

IsTextWrappedMethod · 0.95
GetCharacterHeightFunction · 0.85
ScrollRectFunction · 0.85
WithHeightMethod · 0.80
ShrinkMethod · 0.80
WithWidthMethod · 0.80
TranslateMethod · 0.80
GetPositionMethod · 0.80
GfxFillRectFunction · 0.70
FillDrawPixelInfoFunction · 0.70
DrawStringFunction · 0.70

Tested by

no test coverage detected