Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
Move wxSTC::GotoPos to idle event in fonts collector dialog
Browse files Browse the repository at this point in the history
wxSTC::GotoPos is CPU consuming. Calling it every time when fonts collector worker thread adds log to wxSTC causes performance issues. So we only set a flag to request go to end, and actually do it when idle.

Fix TypesettingTools/Aegisub#28
  • Loading branch information
wangqr committed Jun 4, 2020
1 parent 8af0fc5 commit 17b43f2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dialog_fonts_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class DialogFontsCollector final : public wxDialog {
wxStaticText *dest_label;
wxTextCtrl *dest_ctrl;

bool goto_end_on_idle = false;

void OnStart(wxCommandEvent &);
void OnBrowse(wxCommandEvent &);
void OnRadio(wxCommandEvent &e);
Expand All @@ -77,6 +79,7 @@ class DialogFontsCollector final : public wxDialog {
void OnAddText(ValueEvent<std::pair<int, wxString>>& event);
/// Collection complete notification from the worker thread to reenable buttons
void OnCollectionComplete(wxThreadEvent &);
void OnIdle(wxIdleEvent&);

void UpdateControls();

Expand Down Expand Up @@ -287,6 +290,7 @@ DialogFontsCollector::DialogFontsCollector(agi::Context *c)
button_sizer->GetHelpButton()->Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Fonts Collector"));
Bind(EVT_ADD_TEXT, &DialogFontsCollector::OnAddText, this);
Bind(EVT_COLLECTION_DONE, &DialogFontsCollector::OnCollectionComplete, this);
Bind(wxEVT_IDLE, &DialogFontsCollector::OnIdle, this);
}

void DialogFontsCollector::OnStart(wxCommandEvent &) {
Expand Down Expand Up @@ -407,8 +411,8 @@ void DialogFontsCollector::OnAddText(ValueEvent<color_str_pair> &event) {
#endif
collection_log->SetStyling(utf8.length(), str.first);
}
collection_log->GotoPos(pos + utf8.length());
collection_log->SetReadOnly(true);
goto_end_on_idle = true;
}

void DialogFontsCollector::OnCollectionComplete(wxThreadEvent &) {
Expand All @@ -421,6 +425,13 @@ void DialogFontsCollector::OnCollectionComplete(wxThreadEvent &) {

UpdateControls();
}

void DialogFontsCollector::OnIdle(wxIdleEvent&) {
if (goto_end_on_idle) {
goto_end_on_idle = false;
collection_log->GotoPos(collection_log->GetLength());
}
}
}

void ShowFontsCollectorDialog(agi::Context *c) {
Expand Down

0 comments on commit 17b43f2

Please sign in to comment.