From e11bd3f659eb5ddcc6a910de234a3dfce530ad0f Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Fri, 14 Nov 2008 01:21:17 +0000 Subject: [PATCH] Optimized the audio display redraw. Originally committed to SVN as r2453. --- aegisub/audio_display.cpp | 24 +++++++++++++++++++----- aegisub/audio_display.h | 4 ++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/aegisub/audio_display.cpp b/aegisub/audio_display.cpp index 41ae1821e..6188a40ea 100644 --- a/aegisub/audio_display.cpp +++ b/aegisub/audio_display.cpp @@ -103,6 +103,7 @@ AudioDisplay::AudioDisplay(wxWindow *parent) hold = 0; samples = 0; hasFocus = (wxWindow::FindFocus() == this); + needImageUpdate = false; // Init UpdateTimer.SetOwner(this,Audio_Update_Timer); @@ -159,9 +160,23 @@ void AudioDisplay::Reset() { //////////////// // Update image void AudioDisplay::UpdateImage(bool weak) { + // Update samples + UpdateSamples(); + + // Set image as needing to be redrawn + needImageUpdate = true; + if (!needImageUpdateWeak) needImageUpdateWeak = weak; + Refresh(false); +} + +void AudioDisplay::DoUpdateImage() { // Loaded? if (!loaded || !provider) return; + // Needs updating? + if (!needImageUpdate) return; + bool weak = needImageUpdateWeak; + // Prepare bitmap int timelineHeight = Options.AsBool(_T("Audio Draw Timeline")) ? 20 : 0; int displayH = h+timelineHeight; @@ -189,9 +204,6 @@ void AudioDisplay::UpdateImage(bool weak) { spectrum = true; } - // Update samples - UpdateSamples(); - // Draw image to be displayed wxMemoryDC dc; dc.SelectObject(*origImage); @@ -372,7 +384,8 @@ void AudioDisplay::UpdateImage(bool weak) { } // Done - Refresh(false); + needImageUpdate = false; + needImageUpdateWeak = false; } @@ -1313,6 +1326,7 @@ END_EVENT_TABLE() // Paint void AudioDisplay::OnPaint(wxPaintEvent& event) { if (w == 0 || h == 0) return; + DoUpdateImage(); wxPaintDC dc(this); dc.DrawBitmap(*origImage,0,0); @@ -1397,7 +1411,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) { } // Cursor drawing - if (!player->IsPlaying()) { + if (!player->IsPlaying() && origImage) { // Draw bg wxClientDC dc(this); dc.DrawBitmap(*origImage,0,0); diff --git a/aegisub/audio_display.h b/aegisub/audio_display.h index 4e9234732..1bb9bc113 100644 --- a/aegisub/audio_display.h +++ b/aegisub/audio_display.h @@ -84,6 +84,9 @@ private: bool blockUpdate; bool dontReadTimes; + bool needImageUpdate; + bool needImageUpdateWeak; + bool hasSel; bool hasKaraoke; bool diagUpdated; @@ -130,6 +133,7 @@ private: void UpdatePosition(int pos,bool IsSample=false); int GetBoundarySnap(int x,int range,bool shiftHeld,bool start=true); + void DoUpdateImage(); public: AudioProvider *provider;