* Draw the AI/GS log. * @param r Rect area to draw within. */
| 854 | * @param r Rect area to draw within. |
| 855 | */ |
| 856 | void DrawWidgetLog(const Rect &r) const |
| 857 | { |
| 858 | if (this->filter.script_debug_company == CompanyID::Invalid()) return; |
| 859 | |
| 860 | const ScriptLogTypes::LogData &log = this->GetLogData(); |
| 861 | if (log.empty()) return; |
| 862 | |
| 863 | Rect fr = r.Shrink(WidgetDimensions::scaled.framerect); |
| 864 | |
| 865 | /* Setup a clipping rectangle... */ |
| 866 | DrawPixelInfo tmp_dpi; |
| 867 | if (!FillDrawPixelInfo(&tmp_dpi, fr)) return; |
| 868 | /* ...but keep coordinates relative to the window. */ |
| 869 | tmp_dpi.left += fr.left; |
| 870 | tmp_dpi.top += fr.top; |
| 871 | |
| 872 | AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); |
| 873 | |
| 874 | fr = ScrollRect(fr, *this->hscroll, 1); |
| 875 | |
| 876 | auto [first, last] = this->vscroll->GetVisibleRangeIterators(log); |
| 877 | for (auto it = first; it != last; ++it) { |
| 878 | const ScriptLogTypes::LogLine &line = *it; |
| 879 | |
| 880 | TextColour colour; |
| 881 | switch (line.type) { |
| 882 | case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break; |
| 883 | case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break; |
| 884 | case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break; |
| 885 | case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break; |
| 886 | case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break; |
| 887 | default: colour = TC_BLACK; break; |
| 888 | } |
| 889 | |
| 890 | /* Check if the current line should be highlighted */ |
| 891 | if (std::distance(std::begin(log), it) == this->highlight_row) { |
| 892 | fr.bottom = fr.top + this->resize.step_height - 1; |
| 893 | GfxFillRect(fr, PC_BLACK); |
| 894 | if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white. |
| 895 | } |
| 896 | |
| 897 | DrawString(fr, line.text, colour, SA_LEFT | SA_FORCE); |
| 898 | fr.top += this->resize.step_height; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * Update the scrollbar and scroll position of the log panel. |
no test coverage detected