Split AudioDisplay::OnPaint into several methods

Originally committed to SVN as r6251.
This commit is contained in:
Thomas Goyne 2012-01-08 01:36:58 +00:00
parent 3c62a38c7a
commit 702d1e9c22
2 changed files with 166 additions and 128 deletions

View file

@ -845,12 +845,7 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
return; return;
} }
int client_width, client_height; wxRect audio_bounds(0, audio_top, GetClientSize().GetWidth(), audio_height);
GetClientSize(&client_width, &client_height);
wxRect audio_bounds(0, audio_top, client_width, audio_height);
const wxRect &scrollbar_bounds = scrollbar->GetBounds();
const wxRect &timeline_bounds = timeline->GetBounds();
bool redraw_scrollbar = false; bool redraw_scrollbar = false;
bool redraw_timeline = false; bool redraw_timeline = false;
@ -864,18 +859,34 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
updrect.x += client_org.x; updrect.y += client_org.y; updrect.x += client_org.x; updrect.y += client_org.y;
#endif #endif
redraw_scrollbar |= scrollbar_bounds.Intersects(updrect); redraw_scrollbar |= scrollbar->GetBounds().Intersects(updrect);
redraw_timeline |= timeline_bounds.Intersects(updrect); redraw_timeline |= timeline->GetBounds().Intersects(updrect);
if (!audio_bounds.Intersects(updrect)) if (audio_bounds.Intersects(updrect))
{ {
continue;
}
SampleRange updsamples( SampleRange updsamples(
SamplesFromRelativeX(updrect.x - foot_size), SamplesFromRelativeX(updrect.x - foot_size),
SamplesFromRelativeX(updrect.x + updrect.width + foot_size)); SamplesFromRelativeX(updrect.x + updrect.width + foot_size));
PaintAudio(dc, updsamples, updrect);
PaintMarkers(dc, updsamples);
PaintLabels(dc, updsamples);
}
}
if (track_cursor_pos >= 0)
{
PaintTrackCursor(dc);
}
if (redraw_scrollbar)
scrollbar->Paint(dc, HasFocus());
if (redraw_timeline)
timeline->Paint(dc);
}
void AudioDisplay::PaintAudio(wxDC &dc, SampleRange updsamples, wxRect updrect)
{
std::map<int64_t, int>::iterator pt = style_ranges.upper_bound(updsamples.begin()); std::map<int64_t, int>::iterator pt = style_ranges.upper_bound(updsamples.begin());
std::map<int64_t, int>::iterator pe = style_ranges.upper_bound(updsamples.end()); std::map<int64_t, int>::iterator pe = style_ranges.upper_bound(updsamples.end());
@ -893,41 +904,50 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
audio_renderer->Render(dc, wxPoint(range_x1, audio_top), range_x1 + scroll_left, range_x2 - range_x1, range_style); audio_renderer->Render(dc, wxPoint(range_x1, audio_top), range_x1 + scroll_left, range_x2 - range_x1, range_style);
} }
} }
}
// Draw markers on top of it all void AudioDisplay::PaintMarkers(wxDC &dc, SampleRange updsamples)
{
AudioMarkerVector markers; AudioMarkerVector markers;
controller->GetMarkers(updsamples, markers); controller->GetMarkers(updsamples, markers);
if (markers.empty()) return;
wxDCPenChanger pen_retainer(dc, wxPen()); wxDCPenChanger pen_retainer(dc, wxPen());
wxDCBrushChanger brush_retainer(dc, wxBrush()); wxDCBrushChanger brush_retainer(dc, wxBrush());
for (AudioMarkerVector::iterator marker_i = markers.begin(); marker_i != markers.end(); ++marker_i) for (AudioMarkerVector::iterator marker_i = markers.begin(); marker_i != markers.end(); ++marker_i)
{ {
const AudioMarker *marker = *marker_i; const AudioMarker *marker = *marker_i;
dc.SetPen(marker->GetStyle());
int marker_x = RelativeXFromSamples(marker->GetPosition()); int marker_x = RelativeXFromSamples(marker->GetPosition());
dc.SetPen(marker->GetStyle());
dc.DrawLine(marker_x, audio_top, marker_x, audio_top+audio_height); dc.DrawLine(marker_x, audio_top, marker_x, audio_top+audio_height);
if (marker->GetFeet() == AudioMarker::Feet_None) continue;
dc.SetBrush(wxBrush(marker->GetStyle().GetColour())); dc.SetBrush(wxBrush(marker->GetStyle().GetColour()));
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
if (marker->GetFeet() & AudioMarker::Feet_Left)
{
wxPoint foot_top[3] = { wxPoint(-foot_size, 0), wxPoint(0, 0), wxPoint(0, foot_size) };
wxPoint foot_bot[3] = { wxPoint(-foot_size, 0), wxPoint(0, -foot_size), wxPoint(0, 0) };
dc.DrawPolygon(3, foot_top, marker_x, audio_top);
dc.DrawPolygon(3, foot_bot, marker_x, audio_top+audio_height);
}
if (marker->GetFeet() & AudioMarker::Feet_Right)
{
wxPoint foot_top[3] = { wxPoint(foot_size, 0), wxPoint(0, 0), wxPoint(0, foot_size) };
wxPoint foot_bot[3] = { wxPoint(foot_size, 0), wxPoint(0, -foot_size), wxPoint(0, 0) };
dc.DrawPolygon(3, foot_top, marker_x, audio_top);
dc.DrawPolygon(3, foot_bot, marker_x, audio_top+audio_height);
}
}
// Draw labels if (marker->GetFeet() & AudioMarker::Feet_Left)
PaintFoot(dc, marker_x, -1);
if (marker->GetFeet() & AudioMarker::Feet_Right)
PaintFoot(dc, marker_x, 1);
}
}
void AudioDisplay::PaintFoot(wxDC &dc, int marker_x, int dir)
{
wxPoint foot_top[3] = { wxPoint(foot_size * dir, 0), wxPoint(0, 0), wxPoint(0, foot_size) };
wxPoint foot_bot[3] = { wxPoint(foot_size * dir, 0), wxPoint(0, -foot_size), wxPoint(0, 0) };
dc.DrawPolygon(3, foot_top, marker_x, audio_top);
dc.DrawPolygon(3, foot_bot, marker_x, audio_top+audio_height);
}
void AudioDisplay::PaintLabels(wxDC &dc, SampleRange updsamples)
{
std::vector<AudioLabelProvider::AudioLabel> labels; std::vector<AudioLabelProvider::AudioLabel> labels;
controller->GetLabels(updsamples, labels); controller->GetLabels(updsamples, labels);
if (!labels.empty()) if (labels.empty()) return;
{
wxDCFontChanger fc(dc); wxDCFontChanger fc(dc);
wxFont font = dc.GetFont(); wxFont font = dc.GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD); font.SetWeight(wxFONTWEIGHT_BOLD);
@ -952,16 +972,14 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
dc.DrawText(labels[i].text, left + (width - extent.GetWidth()) / 2, audio_top + 4); dc.DrawText(labels[i].text, left + (width - extent.GetWidth()) / 2, audio_top + 4);
} }
} }
} }
}
if (track_cursor_pos >= 0) void AudioDisplay::PaintTrackCursor(wxDC &dc) {
{
wxDCPenChanger penchanger(dc, wxPen(*wxWHITE)); wxDCPenChanger penchanger(dc, wxPen(*wxWHITE));
dc.DrawLine(track_cursor_pos-scroll_left, audio_top, track_cursor_pos-scroll_left, audio_top+audio_height); dc.DrawLine(track_cursor_pos-scroll_left, audio_top, track_cursor_pos-scroll_left, audio_top+audio_height);
if (!track_cursor_label.empty()) if (track_cursor_label.empty()) return;
{
wxDCFontChanger fc(dc); wxDCFontChanger fc(dc);
wxFont font = dc.GetFont(); wxFont font = dc.GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD); font.SetWeight(wxFONTWEIGHT_BOLD);
@ -969,23 +987,25 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
wxSize label_size(dc.GetTextExtent(track_cursor_label)); wxSize label_size(dc.GetTextExtent(track_cursor_label));
wxPoint label_pos(track_cursor_pos - scroll_left - label_size.x/2, audio_top + 2); wxPoint label_pos(track_cursor_pos - scroll_left - label_size.x/2, audio_top + 2);
if (label_pos.x < 2) label_pos.x = 2; label_pos.x = mid(2, label_pos.x, GetClientSize().GetWidth() - label_size.x - 2);
if (label_pos.x + label_size.x >= client_width - 2) label_pos.x = client_width - label_size.x - 2;
int old_bg_mode = dc.GetBackgroundMode(); int old_bg_mode = dc.GetBackgroundMode();
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
// Draw border // Draw border
dc.SetTextForeground(wxColour(64, 64, 64)); dc.SetTextForeground(wxColour(64, 64, 64));
dc.DrawText(track_cursor_label, label_pos.x+1, label_pos.y+1); dc.DrawText(track_cursor_label, label_pos.x+1, label_pos.y+1);
dc.DrawText(track_cursor_label, label_pos.x+1, label_pos.y-1); dc.DrawText(track_cursor_label, label_pos.x+1, label_pos.y-1);
dc.DrawText(track_cursor_label, label_pos.x-1, label_pos.y+1); dc.DrawText(track_cursor_label, label_pos.x-1, label_pos.y+1);
dc.DrawText(track_cursor_label, label_pos.x-1, label_pos.y-1); dc.DrawText(track_cursor_label, label_pos.x-1, label_pos.y-1);
// Draw fill // Draw fill
dc.SetTextForeground(*wxWHITE); dc.SetTextForeground(*wxWHITE);
dc.DrawText(track_cursor_label, label_pos.x, label_pos.y); dc.DrawText(track_cursor_label, label_pos.x, label_pos.y);
dc.SetBackgroundMode(old_bg_mode); dc.SetBackgroundMode(old_bg_mode);
label_pos.x -= 2; label_pos.y -= 2; label_pos.x -= 2;
label_pos.y -= 2;
label_size.IncBy(4, 4); label_size.IncBy(4, 4);
// If the rendered text changes size we have to draw it an extra time to make sure the entire thing was drawn // If the rendered text changes size we have to draw it an extra time to make sure the entire thing was drawn
bool need_extra_redraw = track_cursor_label_rect.GetSize() != label_size; bool need_extra_redraw = track_cursor_label_rect.GetSize() != label_size;
@ -993,16 +1013,8 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
track_cursor_label_rect.SetSize(label_size); track_cursor_label_rect.SetSize(label_size);
if (need_extra_redraw) if (need_extra_redraw)
RefreshRect(track_cursor_label_rect, false); RefreshRect(track_cursor_label_rect, false);
}
}
if (redraw_scrollbar)
scrollbar->Paint(dc, HasFocus());
if (redraw_timeline)
timeline->Paint(dc);
} }
void AudioDisplay::SetDraggedObject(AudioDisplayInteractionObject *new_obj) void AudioDisplay::SetDraggedObject(AudioDisplayInteractionObject *new_obj)
{ {
dragged_object = new_obj; dragged_object = new_obj;

View file

@ -184,6 +184,32 @@ class AudioDisplay: public wxWindow {
/// @param sample_end Last sample to repaint /// @param sample_end Last sample to repaint
void Redraw(int64_t sample_start, int64_t sample_end); void Redraw(int64_t sample_start, int64_t sample_end);
/// Paint the audio data for a range of samples
/// @param dc DC to paint to
/// @param updsamples Sample range to repaint
/// @param updrect Pixel range to repaint
void PaintAudio(wxDC &dc, SampleRange updsamples, wxRect updrect);
/// Paint the markers in a range of samples
/// @param dc DC to paint to
/// @param updsamples Sample range to repaint
void PaintMarkers(wxDC &dc, SampleRange updsamples);
/// Draw a single foot for a marker
/// @param dc DC to paint to
/// @param marker_x Position of the marker whose foot is being painted in pixels
/// @param dir -1 for left, 1 for right
void PaintFoot(wxDC &dc, int marker_x, int dir);
/// Paint the labels in a range of samples
/// @param dc DC to paint to
/// @param updsamples Sample range to repaint
void PaintLabels(wxDC &dc, SampleRange updsamples);
/// Paint the track cursor
/// @param dc DC to paint to
void PaintTrackCursor(wxDC &dc);
/// wxWidgets paint event /// wxWidgets paint event
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
/// wxWidgets mouse input event /// wxWidgets mouse input event