+
+
+wxString
+time_to_timecode (DCPTime t, double fps)
+{
+ auto w = t.seconds ();
+ int const h = (w / 3600);
+ w -= h * 3600;
+ int const m = (w / 60);
+ w -= m * 60;
+ int const s = floor (w);
+ w -= s;
+ int const f = lrint (w * fps);
+ return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
+}
+
+
+void
+setup_audio_channels_choice (wxChoice* choice, int minimum)
+{
+ vector<pair<string, string>> items;
+ for (int i = minimum; i <= 16; i += 2) {
+ if (i == 2) {
+ items.push_back (make_pair(wx_to_std(_("2 - stereo")), locale_convert<string>(i)));
+ } else if (i == 4) {
+ items.push_back (make_pair(wx_to_std(_("4 - L/C/R/Lfe")), locale_convert<string>(i)));
+ } else if (i == 6) {
+ items.push_back (make_pair(wx_to_std(_("6 - 5.1")), locale_convert<string>(i)));
+ } else if (i == 8) {
+ items.push_back (make_pair(wx_to_std(_("8 - 5.1/HI/VI")), locale_convert<string>(i)));
+ } else if (i == 12) {
+ items.push_back (make_pair(wx_to_std(_("12 - 7.1/HI/VI")), locale_convert<string>(i)));
+ } else {
+ items.push_back (make_pair(locale_convert<string> (i), locale_convert<string>(i)));
+ }
+ }
+
+ checked_set (choice, items);
+}
+
+
+wxSplashScreen*
+maybe_show_splash ()
+{
+ wxSplashScreen* splash = nullptr;
+
+ try {
+ wxBitmap bitmap;
+ if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) {
+ {
+ /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */
+ wxMemoryDC dc(bitmap);
+ auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit);
+ auto screen_size = dc.GetSize();
+ auto text_size = dc.GetTextExtent(version);
+ dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236);
+ }
+#ifdef DCPOMATIC_WINDOWS
+ /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */
+ splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
+#else
+ splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1);
+#endif
+ wxYield ();
+ }
+ } catch (boost::filesystem::filesystem_error& e) {
+ /* Maybe we couldn't find the splash image; never mind */
+ }
+
+ return splash;
+}
+
+
+double
+calculate_mark_interval (double mark_interval)
+{
+ if (mark_interval > 5) {
+ mark_interval -= lrint (mark_interval) % 5;
+ }
+ if (mark_interval > 10) {
+ mark_interval -= lrint (mark_interval) % 10;
+ }
+ if (mark_interval > 60) {
+ mark_interval -= lrint (mark_interval) % 60;
+ }
+ if (mark_interval > 3600) {
+ mark_interval -= lrint (mark_interval) % 3600;
+ }
+
+ if (mark_interval < 1) {
+ mark_interval = 1;
+ }
+
+ return mark_interval;
+}
+
+
+/** @return false if the task was cancelled */
+bool
+display_progress (wxString title, wxString task)
+{
+ auto jm = JobManager::instance ();
+
+ wxProgressDialog progress (title, task, 100, 0, wxPD_CAN_ABORT);
+
+ bool ok = true;
+
+ while (jm->work_to_do()) {
+ dcpomatic_sleep_seconds (1);
+ if (!progress.Pulse()) {
+ /* user pressed cancel */
+ for (auto i: jm->get()) {
+ i->cancel();
+ }
+ ok = false;
+ break;
+ }
+ }
+
+ return ok;
+}
+
+
+int
+get_offsets (vector<Offset>& offsets)
+{
+ offsets.push_back (Offset(_("UTC-11"), -11, 0));
+ offsets.push_back (Offset(_("UTC-10"), -10, 0));
+ offsets.push_back (Offset(_("UTC-9"), -9, 0));
+ offsets.push_back (Offset(_("UTC-8"), -8, 0));
+ offsets.push_back (Offset(_("UTC-7"), -7, 0));
+ offsets.push_back (Offset(_("UTC-6"), -6, 0));
+ offsets.push_back (Offset(_("UTC-5"), -5, 0));
+ offsets.push_back (Offset(_("UTC-4:30"), -4, 30));
+ offsets.push_back (Offset(_("UTC-4"), -4, 0));
+ offsets.push_back (Offset(_("UTC-3:30"), -3, 30));
+ offsets.push_back (Offset(_("UTC-3"), -3, 0));
+ offsets.push_back (Offset(_("UTC-2"), -2, 0));
+ offsets.push_back (Offset(_("UTC-1"), -1, 0));
+ int utc = offsets.size();
+ offsets.push_back (Offset(_("UTC") , 0, 0));
+ offsets.push_back (Offset(_("UTC+1"), 1, 0));
+ offsets.push_back (Offset(_("UTC+2"), 2, 0));
+ offsets.push_back (Offset(_("UTC+3"), 3, 0));
+ offsets.push_back (Offset(_("UTC+4"), 4, 0));
+ offsets.push_back (Offset(_("UTC+5"), 5, 0));
+ offsets.push_back (Offset(_("UTC+5:30"), 5, 30));
+ offsets.push_back (Offset(_("UTC+6"), 6, 0));
+ offsets.push_back (Offset(_("UTC+7"), 7, 0));
+ offsets.push_back (Offset(_("UTC+8"), 8, 0));
+ offsets.push_back (Offset(_("UTC+9"), 9, 0));
+ offsets.push_back (Offset(_("UTC+9:30"), 9, 30));
+ offsets.push_back (Offset(_("UTC+10"), 10, 0));
+ offsets.push_back (Offset(_("UTC+11"), 11, 0));
+ offsets.push_back (Offset(_("UTC+12"), 12, 0));
+
+ return utc;
+}
+
+
+wxString
+bitmap_path (string name)
+{
+ boost::filesystem::path base;
+
+#ifdef DCPOMATIC_DEBUG
+ /* Hack to allow Linux and OS X to find icons when running from the source tree */
+ char* path = getenv ("DCPOMATIC_GRAPHICS");
+ if (path) {
+ base = path;
+ } else {
+ base = resources_path();
+ }
+#else
+ base = resources_path();
+#endif
+
+ auto p = base / name;
+ return std_to_wx (p.string());
+}
+
+
+wxString
+icon_path(string name)
+{
+ return gui_is_dark() ? bitmap_path(String::compose("%1_white.png", name)) : bitmap_path(String::compose("%1_black.png", name));
+}
+
+
+wxSize
+small_button_size (wxWindow* parent, wxString text)
+{
+ wxClientDC dc (parent);
+ auto size = dc.GetTextExtent (text);
+ size.SetHeight (-1);
+ size.IncBy (32, 0);
+ return size;
+}
+
+
+bool
+gui_is_dark ()
+{
+#if defined(DCPOMATIC_OSX) && wxCHECK_VERSION(3, 1, 0)
+ auto appearance = wxSystemSettings::GetAppearance();
+ return appearance.IsDark();
+#else
+ return false;
+#endif
+}
+
+
+#if wxCHECK_VERSION(3,1,0)
+double
+dpi_scale_factor (wxWindow* window)
+{
+ return window->GetDPIScaleFactor();
+}
+#else
+double
+dpi_scale_factor (wxWindow*)
+{
+ return 1;
+}
+#endif
+
+
+
+int
+search_ctrl_height ()
+{
+#ifdef __WXGTK3__
+ return 30;
+#else
+ return -1;
+#endif
+}
+
+
+void
+report_config_load_failure(wxWindow* parent, Config::LoadFailure what)
+{
+ switch (what) {
+ case Config::LoadFailure::CONFIG:
+ message_dialog(parent, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
+ break;
+ case Config::LoadFailure::CINEMAS:
+ message_dialog(
+ parent,
+ _(wxString::Format("The cinemas list for creating KDMs (cinemas.xml) failed to load. Please check the numbered backup files in %s",
+ std_to_wx(Config::instance()->cinemas_file().parent_path().string())))
+ );
+ break;
+ case Config::LoadFailure::DKDM_RECIPIENTS:
+ message_dialog(
+ parent,
+ _(wxString::Format("The recipients list for creating DKDMs (dkdm_recipients.xml) failed to load. Please check the numbered backup files in %s",
+ std_to_wx(Config::instance()->dkdm_recipients_file().parent_path().string())))
+ );
+ break;
+ }
+}
+