X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftimecode.h;h=1d1d6a7f530da0ee03d8732a322151fda7ee22cb;hb=5f2a57d1c21c3e8067dfd1f68505b1bf96e1d7c7;hp=bebfa3f5f8d2f00c3cdea476a5b7e6fde8f9b9ae;hpb=16a7ea91e973b327735658857cbf996cc740be77;p=dcpomatic.git diff --git a/src/wx/timecode.h b/src/wx/timecode.h index bebfa3f5f..1d1d6a7f5 100644 --- a/src/wx/timecode.h +++ b/src/wx/timecode.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,28 +17,80 @@ */ -#include -#include +#ifndef DCPOMATIC_WX_TIMECODE_H +#define DCPOMATIC_WX_TIMECODE_H + +#include "wx_util.h" #include "lib/types.h" +#include +#include +#include -class Timecode : public wxPanel +class TimecodeBase : public wxPanel { public: - Timecode (wxWindow *); + TimecodeBase (wxWindow *); + + void clear (); - void set (Time, int); - Time get (int) const; + void set_editable (bool); boost::signals2::signal Changed; -private: +protected: void changed (); void set_clicked (); + wxSizer* _sizer; + wxPanel* _editable; wxTextCtrl* _hours; wxTextCtrl* _minutes; wxTextCtrl* _seconds; wxTextCtrl* _frames; wxButton* _set_button; + wxStaticText* _fixed; +}; + +template +class Timecode : public TimecodeBase +{ +public: + Timecode (wxWindow* parent) + : TimecodeBase (parent) + { + + } + + void set (T t, float fps) + { + int h; + int m; + int s; + int f; + t.split (fps, h, m, s, f); + + checked_set (_hours, boost::lexical_cast (h)); + checked_set (_minutes, boost::lexical_cast (m)); + checked_set (_seconds, boost::lexical_cast (s)); + checked_set (_frames, boost::lexical_cast (f)); + + _fixed->SetLabel (std_to_wx (t.timecode (fps))); + } + + T get (int fps) const + { + T t; + std::string const h = wx_to_std (_hours->GetValue ()); + t += T::from_seconds (boost::lexical_cast (h.empty() ? "0" : h) * 3600); + std::string const m = wx_to_std (_minutes->GetValue()); + t += T::from_seconds (boost::lexical_cast (m.empty() ? "0" : m) * 60); + std::string const s = wx_to_std (_seconds->GetValue()); + t += T::from_seconds (boost::lexical_cast (s.empty() ? "0" : s)); + std::string const f = wx_to_std (_frames->GetValue()); + t += T::from_seconds (boost::lexical_cast (f.empty() ? "0" : f) / fps); + + return t; + } }; +#endif