00001
00002 #include "wxVideoControl.h"
00003
00004
00005
00006
00007 #include <wx/wxprec.h>
00008 #include <wx/utils.h>
00009
00010 #ifdef __BORLANDC__
00011 #pragma hdrstop
00012 #endif
00013
00014 #ifndef WX_PRECOMP
00015 #include <wx/wx.h>
00016 #endif
00017
00018 #include <vcl_cassert.h>
00019 #include <vgui/vgui_message.h>
00020 #include "bitmaps/prev.xpm"
00021 #include "bitmaps/play.xpm"
00022 #include "bitmaps/pause.xpm"
00023 #include "bitmaps/next.xpm"
00024
00025 #include <vcl_iostream.h>
00026
00027
00028 IMPLEMENT_DYNAMIC_CLASS( wxVideoControl, wxPanel )
00029
00030
00031
00032 BEGIN_EVENT_TABLE( wxVideoControl, wxPanel )
00033 EVT_SCROLL_THUMBTRACK( wxVideoControl::OnSliderTrack )
00034 EVT_SCROLL_PAGEDOWN( wxVideoControl::OnSliderTrack )
00035 EVT_SCROLL_PAGEUP( wxVideoControl::OnSliderTrack )
00036 EVT_SCROLL_LINEDOWN( wxVideoControl::OnSliderTrack )
00037 EVT_SCROLL_LINEUP( wxVideoControl::OnSliderTrack )
00038 EVT_SCROLL_THUMBRELEASE( wxVideoControl::OnSliderChange )
00039 EVT_SCROLL_CHANGED( wxVideoControl::OnSliderChange )
00040 EVT_TEXT_ENTER( wxID_ANY, wxVideoControl::OnEnterText )
00041 EVT_BUTTON( wxID_ANY, wxVideoControl::OnButton )
00042 END_EVENT_TABLE()
00043
00044
00045 const char wxVideoControl::m_preview[] = "";
00046 const char wxVideoControl::m_seek[] = "";
00047 const char wxVideoControl::m_next[] = "";
00048 const char wxVideoControl::m_prev[] = "";
00049 const char wxVideoControl::m_play[] = "";
00050 const char wxVideoControl::m_pause[] = "";
00051
00052
00053
00054 wxVideoControl::wxVideoControl()
00055 : send_messages_(true)
00056 {
00057 Init();
00058 }
00059
00060
00061 wxVideoControl::wxVideoControl(wxWindow* parent,
00062 wxWindowID id,
00063 const wxPoint& pos,
00064 const wxSize& size,
00065 long style,
00066 const wxString& name)
00067 : send_messages_(true)
00068 {
00069 Init();
00070 Create(parent, id, pos, size, style, name);
00071 }
00072
00073
00074
00075 bool wxVideoControl::Create(wxWindow* parent,
00076 wxWindowID id,
00077 const wxPoint& pos,
00078 const wxSize& size,
00079 long style,
00080 const wxString& name)
00081 {
00082 wxPanel::Create(parent, id, pos, size, style, name);
00083 CreateControls();
00084 return true;
00085 }
00086
00087
00088
00089 wxVideoControl::~wxVideoControl()
00090 {
00091 }
00092
00093
00094
00095 void wxVideoControl::Init()
00096 {
00097 }
00098
00099
00100
00101 void wxVideoControl::CreateControls()
00102 {
00103 wxBoxSizer* itemBoxSizer = new wxBoxSizer(wxHORIZONTAL);
00104 this->SetSizer(itemBoxSizer);
00105
00106 prev_button_ = new wxBitmapButton(this, wxNewId(), wxBitmap(prev_xpm, wxBITMAP_TYPE_XPM));
00107 itemBoxSizer->Add(prev_button_, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 3);
00108
00109 play_button_ = new wxBitmapButton(this, wxNewId(), wxBitmap(play_xpm, wxBITMAP_TYPE_XPM));
00110 itemBoxSizer->Add(play_button_, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 3);
00111
00112 next_button_ = new wxBitmapButton(this, wxNewId(), wxBitmap(next_xpm, wxBITMAP_TYPE_XPM));
00113 itemBoxSizer->Add(next_button_, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 3);
00114
00115 slider_ = new wxSlider(this, wxNewId(), 0, 0, num_frames_,
00116 wxDefaultPosition, wxSize(100, -1),
00117 wxSL_HORIZONTAL );
00118 itemBoxSizer->Add(slider_, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 3);
00119
00120 frame_text_ = new wxTextCtrl(this, wxNewId(),
00121 wxString::Format(wxT("%d"),frame_),
00122 wxDefaultPosition, wxSize(50, -1), wxTE_PROCESS_ENTER );
00123
00124 int digits = 1;
00125 unsigned int num_frames = num_frames_-1;
00126 while (num_frames/=10)
00127 ++digits;
00128 frame_text_->SetMaxLength(digits);
00129
00130 itemBoxSizer->Add(frame_text_, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 3);
00131
00132 frame_text_->SetValidator( wxTextValidator(wxFILTER_NUMERIC) );
00133
00134 frame_text_->Connect(-1, wxEVT_KILL_FOCUS,
00135 (wxObjectEventFunction)&wxVideoControl::OnKillTextFocus);
00136
00137
00138 slider_->Connect(-1, wxEVT_KEY_DOWN,
00139 (wxObjectEventFunction)&wxVideoControl::OnKeyDown);
00140 }
00141
00142
00143
00144 void wxVideoControl::set_num_frames(unsigned int num_frames)
00145 {
00146 num_frames_ = num_frames;
00147
00148 int digits = 1;
00149 --num_frames;
00150 while (num_frames/=10)
00151 ++digits;
00152 if (slider_)
00153 slider_->SetRange(0,num_frames_-1);
00154 if (frame_text_)
00155 frame_text_->SetMaxLength(digits);
00156 }
00157
00158
00159
00160 void wxVideoControl::set_frame(unsigned int frame, bool send_message)
00161 {
00162 frame_ = frame;
00163 if (slider_ && frame_text_) {
00164 send_messages_ = send_message;
00165 slider_->SetValue(frame_);
00166 frame_text_->SetValue(wxString::Format(wxT("%d"),frame_));
00167 send_messages_ = true;
00168 }
00169 }
00170
00171
00172 bool wxVideoControl::ShowToolTips()
00173 {
00174 return true;
00175 }
00176
00177
00178
00179 void wxVideoControl::OnSliderTrack( wxScrollEvent& event )
00180 {
00181 int spos = event.GetInt();
00182 frame_text_->SetValue(wxString::Format(wxT("%d"),spos));
00183
00184 if (send_messages_)
00185 {
00186 vgui_message m;
00187 m.from = this;
00188 m.user = wxVideoControl::m_preview;
00189 m.data = &spos;
00190 notify(m);
00191 }
00192 }
00193
00194
00195 void wxVideoControl::OnSliderChange( wxScrollEvent& event )
00196 {
00197 frame_ = slider_->GetValue();
00198 if (send_messages_)
00199 {
00200 frame_ = event.GetInt();
00201 vgui_message m;
00202 m.from = this;
00203 m.user = wxVideoControl::m_seek;
00204 m.data = &frame_;
00205 notify(m);
00206 }
00207 }
00208
00209
00210
00211 void wxVideoControl::OnEnterText( wxCommandEvent& event )
00212 {
00213 long fnum;
00214 event.GetString().ToLong(&fnum);
00215 if (fnum < 0)
00216 fnum = 0;
00217 if (fnum >= (long)num_frames_)
00218 fnum = num_frames_-1L;
00219 frame_text_->SetValue(wxString::Format(wxT("%d"),fnum));
00220 frame_ = fnum;
00221 slider_->SetValue(frame_);
00222 if (send_messages_)
00223 {
00224 vgui_message m;
00225 m.from = this;
00226 m.user = wxVideoControl::m_seek;
00227 m.data = &frame_;
00228 notify(m);
00229 }
00230 }
00231
00232
00233
00234 void wxVideoControl::OnButton( wxCommandEvent& event )
00235 {
00236 int id = event.GetId();
00237 if (id == next_button_->GetId())
00238 next();
00239 else if (id == play_button_->GetId()) {
00240 if (is_playing_)
00241 pause();
00242 else
00243 play();
00244 }
00245 else if (id == prev_button_->GetId())
00246 prev();
00247 }
00248
00249
00250
00251 void wxVideoControl::OnKeyDown( wxKeyEvent& event )
00252 {
00253 vcl_cout << "key press!"<<vcl_endl;
00254 }
00255
00256
00257 void wxVideoControl::next()
00258 {
00259 if (frame_ >= num_frames_)
00260 return;
00261 ++frame_;
00262 frame_text_->SetValue(wxString::Format(wxT("%d"),frame_));
00263 slider_->SetValue(frame_);
00264 if (send_messages_)
00265 {
00266 vgui_message m;
00267 m.from = this;
00268 m.user = wxVideoControl::m_next;
00269 m.data = &frame_;
00270 notify(m);
00271 }
00272 }
00273
00274
00275 void wxVideoControl::prev()
00276 {
00277 if (frame_ <= 0)
00278 return;
00279 --frame_;
00280 frame_text_->SetValue(wxString::Format(wxT("%d"),frame_));
00281 slider_->SetValue(frame_);
00282 if (send_messages_)
00283 {
00284 vgui_message m;
00285 m.from = this;
00286 m.user = wxVideoControl::m_prev;
00287 m.data = &frame_;
00288 notify(m);
00289 }
00290 }
00291
00292
00293
00294 void wxVideoControl::play()
00295 {
00296 play_button_->SetBitmapLabel(wxBitmap(pause_xpm, wxBITMAP_TYPE_XPM));
00297 is_playing_ = true;
00298 prev_button_->Disable();
00299 next_button_->Disable();
00300 frame_text_->Disable();
00301 slider_->Disable();
00302 if (send_messages_)
00303 {
00304 vgui_message m;
00305 m.from = this;
00306 m.user = wxVideoControl::m_play;
00307 m.data = &frame_;
00308 notify(m);
00309 }
00310 }
00311
00312
00313 void wxVideoControl::pause()
00314 {
00315 play_button_->SetBitmapLabel(wxBitmap(play_xpm, wxBITMAP_TYPE_XPM));
00316 is_playing_ = false;
00317 prev_button_->Enable();
00318 next_button_->Enable();
00319 frame_text_->Enable();
00320 slider_->Enable();
00321 if (send_messages_)
00322 {
00323 vgui_message m;
00324 m.from = this;
00325 m.user = wxVideoControl::m_pause;
00326 m.data = &frame_;
00327 notify(m);
00328 }
00329 }
00330
00331
00332
00333
00334 void wxVideoControl::OnKillTextFocus( wxCommandEvent& event )
00335 {
00336 wxTextCtrl* text = dynamic_cast<wxTextCtrl*>(FindWindowById(event.GetId()));
00337 wxVideoControl* vc = dynamic_cast<wxVideoControl*>(text->GetParent());
00338 text->SetValue(wxString::Format(wxT("%d"),vc->frame_));
00339 }
00340