| | 62 | |
| | 63 | DEFINE_EVENT_TYPE(AEGISUB_LIBASS_FONTUPDATE_FINISH) |
| | 64 | |
| | 65 | class AegisubLibassFontupdateFinishEvent : public wxEvent { |
| | 66 | public: |
| | 67 | AegisubLibassFontupdateFinishEvent() |
| | 68 | : wxEvent(0, AEGISUB_LIBASS_FONTUPDATE_FINISH) |
| | 69 | { } |
| | 70 | virtual wxEvent *Clone() const { |
| | 71 | return new AegisubLibassFontupdateFinishEvent(*this); |
| | 72 | } |
| | 73 | }; |
| | 74 | |
| | 75 | class LibassFontUpdateThread : public wxThread { |
| | 76 | wxEvtHandler &completion_event_handler; |
| | 77 | |
| | 78 | public: |
| | 79 | LibassFontUpdateThread(wxEvtHandler &completion_event_handler) |
| | 80 | : wxThread(wxTHREAD_DETACHED) |
| | 81 | , completion_event_handler(completion_event_handler) |
| | 82 | { |
| | 83 | Create(); |
| | 84 | Run(); |
| | 85 | } |
| | 86 | |
| | 87 | ExitCode Entry() { |
| | 88 | ass_fonts_update(); |
| | 89 | completeion_event_handler->AddPendingEvent(AegisubLibassFontupdateFinishEvent()); |
| | 90 | } |
| | 91 | }; |
| | 92 | |
| | 93 | |
| | 94 | class LibassFontUpdateStatusDialog : public wxDialog, wxTimer { |
| | 95 | void Notify() { |
| | 96 | Show(); |
| | 97 | } |
| | 98 | |
| | 99 | bool font_update_running; |
| | 100 | |
| | 101 | void OnDoneUpdating(AegisubLibassFontupdateFinishEvent &evt) { |
| | 102 | font_update_running = false; |
| | 103 | } |
| | 104 | |
| | 105 | public: |
| | 106 | LibassFontUpdateStatusDialog() |
| | 107 | : wxDialog(0, -1, _T(""), wxDefaultPos, wxDefaultSize, 0) |
| | 108 | , wxTimer() |
| | 109 | { |
| | 110 | font_update_running = true; |
| | 111 | |
| | 112 | wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL); |
| | 113 | |
| | 114 | main_sizer->Add(new wxStaticText(this, -1, _("Please wait, caching fonts...")), 0, wxEXPAND|wxALL, 12); |
| | 115 | |
| | 116 | wxGauge *gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(350, -1)); |
| | 117 | gauge->Pulse(); |
| | 118 | main_sizer->Add(gauge, 0, wxEXPAND|wxALL&~wxTOP, 12); |
| | 119 | |
| | 120 | SetSizerAndFit(main_sizer); |
| | 121 | Centre(); |
| | 122 | |
| | 123 | Start(2000, true); |
| | 124 | } |
| | 125 | |
| | 126 | void WaitForFontUpdateCompletion() { |
| | 127 | while (app.Pending() || font_update_running) |
| | 128 | { |
| | 129 | Dispatch(); |
| | 130 | } |
| | 131 | Destroy(); |
| | 132 | } |
| | 133 | }; |
| | 134 | |
| | 135 | |
| 96 | | ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 1); |
| | 173 | ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 0); |
| | 174 | |
| | 175 | LibassFontUpdateStatusDialog *fonts_update_dlg = new LibassFontUpdateStatusDialog; |
| | 176 | new LibassFontUpdateThread(fonts_update_dlg); |
| | 177 | wxWindowDisabler win_disabler(fonts_update_dlg); |
| | 178 | fonts_update_dlg->WaitForFontUpdateCompletion(); |