* Update the scrollbar and scroll position of the log panel. */
| 903 | * Update the scrollbar and scroll position of the log panel. |
| 904 | */ |
| 905 | void UpdateLogScroll() |
| 906 | { |
| 907 | this->SetWidgetsDisabledState(this->filter.script_debug_company == CompanyID::Invalid(), WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR); |
| 908 | if (this->filter.script_debug_company == CompanyID::Invalid()) return; |
| 909 | |
| 910 | ScriptLogTypes::LogData &log = this->GetLogData(); |
| 911 | |
| 912 | int scroll_count = static_cast<int>(log.size()); |
| 913 | if (this->vscroll->GetCount() != scroll_count) { |
| 914 | this->vscroll->SetCount(scroll_count); |
| 915 | |
| 916 | /* We need a repaint */ |
| 917 | this->SetWidgetDirty(WID_SCRD_VSCROLLBAR); |
| 918 | } |
| 919 | |
| 920 | if (log.empty()) return; |
| 921 | |
| 922 | /* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */ |
| 923 | if (this->last_vscroll_pos != this->vscroll->GetPosition()) { |
| 924 | this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= static_cast<int>(log.size()); |
| 925 | } |
| 926 | |
| 927 | if (this->autoscroll && this->vscroll->SetPosition(static_cast<int>(log.size()))) { |
| 928 | /* We need a repaint */ |
| 929 | this->SetWidgetDirty(WID_SCRD_VSCROLLBAR); |
| 930 | this->SetWidgetDirty(WID_SCRD_LOG_PANEL); |
| 931 | } |
| 932 | |
| 933 | this->last_vscroll_pos = this->vscroll->GetPosition(); |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Update state of all Company (AI) buttons. |
no test coverage detected