mmboard.cpp

来自「Wxpython Implemented on Windows CE, Sou」· C++ 代码 · 共 592 行 · 第 1/2 页

CPP
592
字号
    wxStaticLine *line = new wxStaticLine(infoPanel, wxID_ANY);
#endif // wxUSE_STATLINE
    m_infoText = new wxStaticText(infoPanel, wxID_ANY, wxEmptyString);

    UpdateInfoText();

    infoSizer->Add(m_fileType, 0, wxGROW | wxALL, 1);
#if wxUSE_STATLINE
    infoSizer->Add(line, 0, wxGROW | wxCENTRE, 20);
#endif // wxUSE_STATLINE
    infoSizer->Add(m_infoText, 0, wxGROW | wxALL, 1);

    infoPanel->SetSizer(infoSizer);

    // Bitmap button panel
    wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);

    wxBitmap play_bmp(play_back_xpm);
    wxBitmap stop_bmp(stop_back_xpm);
    wxBitmap eject_bmp(eject_xpm);
    wxBitmap pause_bmp(pause_xpm);

    m_playButton = new wxBitmapButton(m_panel, MMBoard_PlayButton, play_bmp);
    m_playButton->Disable();
    m_pauseButton = new wxBitmapButton(m_panel, MMBoard_PauseButton, pause_bmp);
    m_pauseButton->Disable();
    m_stopButton = new wxBitmapButton(m_panel, MMBoard_StopButton, stop_bmp);
    m_stopButton->Disable();
    m_ejectButton = new wxBitmapButton(m_panel, MMBoard_EjectButton, eject_bmp);
    m_ejectButton->Disable();

    buttonSizer->Add(m_playButton, 0, wxALL, 2);
    buttonSizer->Add(m_pauseButton, 0, wxALL, 2);
    buttonSizer->Add(m_stopButton, 0, wxALL, 2);
    buttonSizer->Add(m_ejectButton, 0, wxALL, 2);

    // Top sizer
    m_sizer = new wxBoxSizer(wxVERTICAL);
#if wxUSE_STATLINE
    m_sizer->Add(new wxStaticLine(m_panel, wxID_ANY), 0, wxGROW | wxCENTRE, 0);
#endif // wxUSE_STATLINE
    m_sizer->Add(m_positionSlider, 0, wxCENTRE | wxGROW | wxALL, 2);
#if wxUSE_STATLINE
    m_sizer->Add(new wxStaticLine(m_panel, wxID_ANY), 0, wxGROW | wxCENTRE, 0);
#endif // wxUSE_STATLINE
    m_sizer->Add(buttonSizer, 0, wxALL, 0);
#if wxUSE_STATLINE
    m_sizer->Add(new wxStaticLine(m_panel, wxID_ANY), 0, wxGROW | wxCENTRE, 0);
#endif // wxUSE_STATLINE
    m_sizer->Add(infoPanel, 1, wxCENTRE | wxGROW, 0);

    m_panel->SetSizer(m_sizer);
    m_sizer->Fit(this);
    m_sizer->SetSizeHints(this);

    // Timer
    m_refreshTimer = new wxTimer(this, MMBoard_RefreshInfo);

    // Video window
    m_video_window = NULL;

    // Multimedia file
    m_opened_file = NULL;
}

MMBoardFrame::~MMBoardFrame()
{
    if (m_opened_file)
        delete m_opened_file;

    delete m_refreshTimer;
}

void MMBoardFrame::OpenVideoWindow()
{
  if (m_video_window)
    return;

  m_video_window = new wxWindow(m_panel, wxID_ANY, wxDefaultPosition, wxSize(200, 200));
  m_video_window->SetBackgroundColour(*wxBLACK);
  m_sizer->Prepend(m_video_window, 2, wxGROW | wxSHRINK | wxCENTRE, 1);

  m_sizer->Fit(this);
}

void MMBoardFrame::CloseVideoWindow()
{
    if (!m_video_window)
        return;

    m_sizer->Detach( m_video_window );
    delete m_video_window;
    m_video_window = NULL;

    m_sizer->Fit(this);
}

// event handlers

void MMBoardFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

void MMBoardFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxString msg;
    msg.Printf( wxT("wxWidgets Multimedia board v1.0a, wxMMedia v2.0a:\n")
                wxT("an example of the capabilities of the wxWidgets multimedia classes.\n")
        wxT("Copyright 1999, 2000, Guilhem Lavaux.\n"));

    wxMessageBox(msg, _T("About MMBoard"), wxOK | wxICON_INFORMATION, this);
}

void MMBoardFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
{
    wxString selected_file;

    if (m_opened_file) {
        if (!m_opened_file->IsStopped()) {
            wxCommandEvent event2;
            OnStop(event2);
        }
        delete m_opened_file;
    }

    // select a file to be opened
#if wxUSE_FILEDLG
    selected_file = wxLoadFileSelector(_T("multimedia"), _T("*"), NULL, this);
#endif // wxUSE_FILEDLG
    if (selected_file.empty())
        return;

    m_opened_file = MMBoardManager::Open(selected_file);

    // Change the range values of the slider.
    MMBoardTime length;

    length = m_opened_file->GetLength();
    m_positionSlider->SetRange(0, length.hours * 3600 + length.minutes * 60 + length.seconds);

    // Update misc info
    UpdateMMedInfo();

#if wxUSE_STATUSBAR
    SetStatusText(selected_file, 2);
#endif // wxUSE_STATUSBAR

    // Update info text
    UpdateInfoText();

    // Enable a few buttons
    m_playButton->Enable();
    m_ejectButton->Enable();
    m_positionSlider->Enable();

    if (m_opened_file->NeedWindow()) {
        OpenVideoWindow();
        m_opened_file->SetWindow(m_video_window);
    } else
        CloseVideoWindow();
}

void MMBoardFrame::UpdateInfoText()
{
    wxString infotext1, infotext2;

    if (m_opened_file) {
        infotext1 = wxT("File type:\n\t");
        infotext1 += m_opened_file->GetStringType() + wxT("\n");

        infotext2 = wxT("File informations:\n\n");
        infotext2 += m_opened_file->GetStringInformation();
    } else {
        infotext1 = wxT("File type: \n\tNo file opened");
        infotext2 = wxT("File informations:\nNo information\n\n\n\n\n");
    }

    m_fileType->SetLabel(infotext1);
    m_infoText->SetLabel(infotext2);
}

void MMBoardFrame::UpdateMMedInfo()
{
    MMBoardTime current, length;

    if (m_opened_file) {
        current = m_opened_file->GetPosition();
        length  = m_opened_file->GetLength();
    } else {
        current.hours = current.minutes = current.seconds = 0;
        length = current;
    }

#if wxUSE_STATUSBAR
    // We refresh the status bar
    wxString temp_string;
    temp_string.Printf(wxT("%02d:%02d / %02d:%02d"), current.hours * 60 + current.minutes,
                       current.seconds, length.hours * 60 + length.minutes, length.seconds);
    SetStatusText(temp_string, 1);
#else
    wxUnusedVar(length);
#endif // wxUSE_STATUSBAR

    // We set the slider position
    m_positionSlider->SetValue(current.hours * 3600 + current.minutes * 60 + current.seconds);
}

// ----------------------------------------------------------------------------
// Playing management, refreshers, ...

void MMBoardFrame::OnRefreshInfo(wxEvent& WXUNUSED(event))
{
    UpdateMMedInfo();

    if (m_opened_file->IsStopped())
    {
        m_refreshTimer->Stop();
        m_playButton->Enable();
        m_stopButton->Disable();
        m_pauseButton->Disable();
    }
}

void MMBoardFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{
    m_stopButton->Enable();
    m_pauseButton->Enable();
    m_playButton->Disable();

    if (m_opened_file->IsPaused())
    {
        m_opened_file->Resume();
        return;
    }

    m_refreshTimer->Start(1000, false);

    m_opened_file->Play();

    m_stopButton->Enable();
    m_pauseButton->Enable();
    m_playButton->Disable();
}

void MMBoardFrame::OnStop(wxCommandEvent& WXUNUSED(event))
{
    m_opened_file->Stop();
    m_refreshTimer->Stop();

    m_stopButton->Disable();
    m_playButton->Enable();

    UpdateMMedInfo();
}

void MMBoardFrame::OnPause(wxCommandEvent& WXUNUSED(event))
{
    m_opened_file->Pause();

    m_playButton->Enable();
    m_pauseButton->Disable();
}

void MMBoardFrame::OnEject(wxCommandEvent& WXUNUSED(event))
{
    m_opened_file->Stop();

    delete m_opened_file;
    m_opened_file = NULL;

    m_playButton->Disable();
    m_pauseButton->Disable();
    m_stopButton->Disable();
    m_ejectButton->Disable();
    m_positionSlider->Disable();

    UpdateInfoText();
    UpdateMMedInfo();
}

void MMBoardFrame::OnSetPosition(wxCommandEvent& WXUNUSED(event))
{
    wxUint32 itime;
    MMBoardTime btime;

    itime = m_positionSlider->GetValue();
    btime.seconds = itime % 60;
    btime.minutes = (itime / 60) % 60;
    btime.hours = itime / 3600;
    m_opened_file->SetPosition(btime);

    UpdateMMedInfo();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?