forked from mia/Aegisub
Optimized the audio display redraw.
Originally committed to SVN as r2453.
This commit is contained in:
parent
b310869224
commit
e11bd3f659
2 changed files with 23 additions and 5 deletions
|
@ -103,6 +103,7 @@ AudioDisplay::AudioDisplay(wxWindow *parent)
|
||||||
hold = 0;
|
hold = 0;
|
||||||
samples = 0;
|
samples = 0;
|
||||||
hasFocus = (wxWindow::FindFocus() == this);
|
hasFocus = (wxWindow::FindFocus() == this);
|
||||||
|
needImageUpdate = false;
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
UpdateTimer.SetOwner(this,Audio_Update_Timer);
|
UpdateTimer.SetOwner(this,Audio_Update_Timer);
|
||||||
|
@ -159,9 +160,23 @@ void AudioDisplay::Reset() {
|
||||||
////////////////
|
////////////////
|
||||||
// Update image
|
// Update image
|
||||||
void AudioDisplay::UpdateImage(bool weak) {
|
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?
|
// Loaded?
|
||||||
if (!loaded || !provider) return;
|
if (!loaded || !provider) return;
|
||||||
|
|
||||||
|
// Needs updating?
|
||||||
|
if (!needImageUpdate) return;
|
||||||
|
bool weak = needImageUpdateWeak;
|
||||||
|
|
||||||
// Prepare bitmap
|
// Prepare bitmap
|
||||||
int timelineHeight = Options.AsBool(_T("Audio Draw Timeline")) ? 20 : 0;
|
int timelineHeight = Options.AsBool(_T("Audio Draw Timeline")) ? 20 : 0;
|
||||||
int displayH = h+timelineHeight;
|
int displayH = h+timelineHeight;
|
||||||
|
@ -189,9 +204,6 @@ void AudioDisplay::UpdateImage(bool weak) {
|
||||||
spectrum = true;
|
spectrum = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update samples
|
|
||||||
UpdateSamples();
|
|
||||||
|
|
||||||
// Draw image to be displayed
|
// Draw image to be displayed
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
dc.SelectObject(*origImage);
|
dc.SelectObject(*origImage);
|
||||||
|
@ -372,7 +384,8 @@ void AudioDisplay::UpdateImage(bool weak) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Refresh(false);
|
needImageUpdate = false;
|
||||||
|
needImageUpdateWeak = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1313,6 +1326,7 @@ END_EVENT_TABLE()
|
||||||
// Paint
|
// Paint
|
||||||
void AudioDisplay::OnPaint(wxPaintEvent& event) {
|
void AudioDisplay::OnPaint(wxPaintEvent& event) {
|
||||||
if (w == 0 || h == 0) return;
|
if (w == 0 || h == 0) return;
|
||||||
|
DoUpdateImage();
|
||||||
|
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
dc.DrawBitmap(*origImage,0,0);
|
dc.DrawBitmap(*origImage,0,0);
|
||||||
|
@ -1397,7 +1411,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cursor drawing
|
// Cursor drawing
|
||||||
if (!player->IsPlaying()) {
|
if (!player->IsPlaying() && origImage) {
|
||||||
// Draw bg
|
// Draw bg
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
dc.DrawBitmap(*origImage,0,0);
|
dc.DrawBitmap(*origImage,0,0);
|
||||||
|
|
|
@ -84,6 +84,9 @@ private:
|
||||||
bool blockUpdate;
|
bool blockUpdate;
|
||||||
bool dontReadTimes;
|
bool dontReadTimes;
|
||||||
|
|
||||||
|
bool needImageUpdate;
|
||||||
|
bool needImageUpdateWeak;
|
||||||
|
|
||||||
bool hasSel;
|
bool hasSel;
|
||||||
bool hasKaraoke;
|
bool hasKaraoke;
|
||||||
bool diagUpdated;
|
bool diagUpdated;
|
||||||
|
@ -130,6 +133,7 @@ private:
|
||||||
void UpdatePosition(int pos,bool IsSample=false);
|
void UpdatePosition(int pos,bool IsSample=false);
|
||||||
|
|
||||||
int GetBoundarySnap(int x,int range,bool shiftHeld,bool start=true);
|
int GetBoundarySnap(int x,int range,bool shiftHeld,bool start=true);
|
||||||
|
void DoUpdateImage();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioProvider *provider;
|
AudioProvider *provider;
|
||||||
|
|
Loading…
Reference in a new issue