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

Method UpdateLogScroll

src/script/script_gui.cpp:905–934  ·  view source on GitHub ↗

* Update the scrollbar and scroll position of the log panel. */

Source from the content-addressed store, hash-verified

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.

Callers 1

OnPaintMethod · 0.95

Calls 10

InvalidFunction · 0.85
SetWidgetDirtyMethod · 0.80
GetPositionMethod · 0.80
SetPositionMethod · 0.80
sizeMethod · 0.45
GetCountMethod · 0.45
SetCountMethod · 0.45
emptyMethod · 0.45
GetCapacityMethod · 0.45

Tested by

no test coverage detected