The area that I'm drawing on, is m_TopWaveformPanel. Here is the relevant code,
In the constructor I bind the event like this,
Code: Select all
Bind(wxEVT_PAINT, &MainFrame::PaintEvent, this);
Code: Select all
void MainFrame::PaintEvent(wxPaintEvent& evt)
{
wxPaintDC dc(this);
Render(dc);
}
void MainFrame::PaintNow()
{
wxClientDC dc(this);
Render(dc);
}
void MainFrame::Render(wxDC& dc)
{
int selected_row = m_Library->GetSelectedRow();
if (selected_row < 0)
return;
wxString selected = m_Library->GetTextValue(selected_row, 1);
std::string path = GetFilenamePathAndExtension(selected).Path.ToStdString();
Tags tags(path);
m_TopWaveformPanel->SetDoubleBuffered(true);
int length = tags.GetAudioInfo().length;
wxLogDebug("Len: %d", length);
double position = m_MediaCtrl->Tell();
wxLogDebug("Pos: %f", position);
dc.SetPen(wxPen(wxColor(255,0,0,255), 2, wxPENSTYLE_SOLID));
m_Timer->Start(1, wxTIMER_CONTINUOUS);
int panel_width = m_TopWaveformPanel->GetSize().GetWidth();
double line_pos = panel_width * (position / length);
wxLogDebug("Drawing at: %f", line_pos);
dc.DrawLine(line_pos, m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
line_pos, m_TopWaveformPanel->GetSize().GetHeight() - 1);
}
Code: Select all
void MainFrame::UpdateElapsedTime(wxTimerEvent& event)
{
wxString duration, position;
wxLongLong llLength, llTell;
llLength = m_MediaCtrl->Length();
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
llTell = m_MediaCtrl->Tell();
int current_min = static_cast<int>((llTell / 60000).GetValue());
int current_sec = static_cast<int>(((llTell % 60000) / 1000).GetValue());
duration.Printf(wxT("%2i:%02i"), total_min, total_sec);
position.Printf(wxT("%2i:%02i"), current_min, current_sec);
m_SamplePosition->SetLabel(wxString::Format(wxT("%s/%s"), position.c_str(), duration.c_str()));
// ==================================================
ClearBackground(); <------- Line drawing timer starts here..
PaintNow();
Refresh();
}